Skip to content

GetCertificate

Finds a certificate based on the given context.

1
$Crypto.GetCertificate(cert: [CertificateContext](./CertificateContext/index.md)):`CommonName` : string

The common name of the certificate.

SerialNumber : string
The serial number of the certificate.

Logout() : void
Logs out from the PKCS11 device.

TryLogin(pin: string) : string
Tries to log in to the PKCS11 device with the given PIN.

Loads a certificate from PFX content.

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

The common name of the certificate.

SerialNumber : string
The serial number of the certificate.

Logout() : void
Logs out from the PKCS11 device.

TryLogin(pin: string) : string
Tries to log in to the PKCS11 device with the given PIN.

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 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');