2023-05-17

check x509 Certificate validity

I would like to check validity of a certificate x509 in flutter like this js method.

import tls from 'tls';
import { X509Certificate } from 'crypto'

function validCertificate(cert, key) {
  try {
    tls.createSecureContext({ cert, key })
    const { validTo } = new X509Certificate(cert);
    return new Date(validTo) > new Date()
  }
  catch (error) {
    if (error.code === 'ERR_OSSL_X509_KEY_VALUES_MISMATCH') {
      return false;
    }
    throw error;
  }
}


No comments:

Post a Comment