Skip to content

GetCertificate

Finds a certificate based on the given context.

1
$Crypto.GetCertificate(cert: CertificateContext):Certificate

Loads a certificate from PFX content.

1
$Crypto.GetCertificate(cert: string, password: string):Certificate

Parameters

CertificateContext cert
    The certificate context to use when searching for the certificate.

string password
    The password of the PFX content.

Returns

The certificate if found; otherwise, null. The certificate found in the PFX content.

Remarks

If multiple certificates are found, the first one is returned.
If no certificate is found, null is returned.
An error exception is thrown if the PKCS11 library or PFX file is not found or fails to load.

Finding a certificate from a list:

1
2
3
4
5
6
var cert = $Crypto.GetCertificate({
    Filter: {
        CommonName: 'The Name'
        // SerialNumber : '1234'
    }
});

Loading a certificate from a PKCS11 library:

1
2
3
4
5
6
7
8
var cert = $Crypto.GetCertificate({
    Filter: {
        CommonName: 'The Name'
        // SerialNumber : '1234'
    },
    Pin: '1111',
    Library: '<path to PKCS11 library>'
});

Load a certificate from a PFX file:

1
var cert = $Crypto.GetCertificate('base64 encoded pfx content', 'password');

Types

Certificate

CommonName : string
The common name of the certificate.

SerialNumber : string
The serial number of the certificate.