CertificateManager Class
Properties Methods Events Configuration Settings Errors
The CertificateManager class supports importing, exporting, and generating X.509 certificates.
Syntax
SecureBlackboxCertificateManager
SecureBlackboxCertificateManagerSwift
Remarks
Usage of this class includes importing and exporting certificates and keys in various formats, as well as certificate generation.
Loading certificates
In vast majority of SecureBlackbox-powered projects, this component is used to import certificates from files or memory objects for further use in other components, like PDFSigner.To load a certificate from a file, use the ImportFromFile method. This method supports all existing certificate formats, including PFX, PEM, DER, and P7B. Note that keys contained in PFX and PEM certificates are often encrypted with a password, so you will likely need to provide one for the certificate to be loaded correctly. You can either provide the password via the method's parameter, or provide it on-demand by subscribing to the PasswordNeeded event.
Alternatively, you can use ImportCert to load a certificate from a different type of media, such as a database.
If your certificate and its private key are stored in separate files or buffers - which is often the case where PEM or DER format is used - please load the certificate with the ImportFromFile method first, and then add the key to it with a separate call to the ImportKeyFromFile method. You can mix and match the certificate and key formats in this case; CertificateManager will handle this automatically.
Note that CertificateManager can only keep one certificate at a time. If your PFX or PEM file contains more than one certificate, use CertificateStorage component to load it instead.
Generating certificates
You can use CertificateManager to generate your own certificates. To generate a certificate, please follow the below steps:- set all the needed certificate properties - for example, its subject, serial number, and validity period - via the Certificate property.
- load the CA certificate to a different CertificateManager object, and assign it
to the CACertificate property. Note that the CA certificate should have an associated private key. Alternatively,
the CA certificate can be loaded using a CertificateStorage object, which allows to import it from a hardware device
or a system store.
Note: you do not need to load and set the CA certificate if generating a self-signed certificate.
- Call Generate to generate a new keypair and wrap it into a certificate.
- Save the certificate using ExportToFile or ExportCert methods.
Note: take care to choose a format that supports storing private keys. If you do not save the new private key at this stage, you won't be able to recover it later.
Note: you can save the private key separately using the ExportKey method.
Generating certificate requests
Apart from certificates, CertificateManager can generate certificate requests (PKCS10). The procedure is the same as when generating certificates. The only difference is that you need to use CertificateRequest object to set up the certificate request parameters, and GenerateCSR method to generate the request. You can then save the resulting request to a file using the ExportCSR method.Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
- CACertBytes | Returns raw certificate data in DER format. |
- CACertHandle | Allows to get or set a 'handle', a unique identifier of the underlying property object. |
- certBytes | Returns raw certificate data in DER format. |
- certCA | Indicates whether the certificate has a CA capability (a setting in BasicConstraints extension). |
- certCAKeyID | A unique identifier (fingerprint) of the CA certificate's private key. |
- certCRLDistributionPoints | Locations of the CRL (Certificate Revocation List) distribution points used to check this certificate's validity. |
- certCurve | Specifies the elliptic curve of the EC public key. |
- certFingerprint | Contains the fingerprint (a hash imprint) of this certificate. |
- certFriendlyName | Contains an associated alias (friendly name) of the certificate. |
- certHandle | Allows to get or set a 'handle', a unique identifier of the underlying property object. |
- certHashAlgorithm | Specifies the hash algorithm to be used in the operations on the certificate (such as key signing) SB_HASH_ALGORITHM_SHA1 SHA1 SB_HASH_ALGORITHM_SHA224 SHA224 SB_HASH_ALGORITHM_SHA256 SHA256 SB_HASH_ALGORITHM_SHA384 SHA384 SB_HASH_ALGORITHM_SHA512 SHA512 SB_HASH_ALGORITHM_MD2 MD2 SB_HASH_ALGORITHM_MD4 MD4 SB_HASH_ALGORITHM_MD5 MD5 SB_HASH_ALGORITHM_RIPEMD160 RIPEMD160 SB_HASH_ALGORITHM_CRC32 CRC32 SB_HASH_ALGORITHM_SSL3 SSL3 SB_HASH_ALGORITHM_GOST_R3411_1994 GOST1994 SB_HASH_ALGORITHM_WHIRLPOOL WHIRLPOOL SB_HASH_ALGORITHM_POLY1305 POLY1305 SB_HASH_ALGORITHM_SHA3_224 SHA3_224 SB_HASH_ALGORITHM_SHA3_256 SHA3_256 SB_HASH_ALGORITHM_SHA3_384 SHA3_384 SB_HASH_ALGORITHM_SHA3_512 SHA3_512 SB_HASH_ALGORITHM_BLAKE2S_128 BLAKE2S_128 SB_HASH_ALGORITHM_BLAKE2S_160 BLAKE2S_160 SB_HASH_ALGORITHM_BLAKE2S_224 BLAKE2S_224 SB_HASH_ALGORITHM_BLAKE2S_256 BLAKE2S_256 SB_HASH_ALGORITHM_BLAKE2B_160 BLAKE2B_160 SB_HASH_ALGORITHM_BLAKE2B_256 BLAKE2B_256 SB_HASH_ALGORITHM_BLAKE2B_384 BLAKE2B_384 SB_HASH_ALGORITHM_BLAKE2B_512 BLAKE2B_512 SB_HASH_ALGORITHM_SHAKE_128 SHAKE_128 SB_HASH_ALGORITHM_SHAKE_256 SHAKE_256 SB_HASH_ALGORITHM_SHAKE_128_LEN SHAKE_128_LEN SB_HASH_ALGORITHM_SHAKE_256_LEN SHAKE_256_LEN . |
- certIssuer | The common name of the certificate issuer (CA), typically a company name. |
- certIssuerRDN | A collection of information, in the form of [OID, Value] pairs, uniquely identifying the certificate issuer. |
- certKeyAlgorithm | Specifies the public key algorithm of this certificate. |
- certKeyBits | Returns the length of the public key. |
- certKeyFingerprint | Returns a fingerprint of the public key contained in the certificate. |
- certKeyUsage | Indicates the purposes of the key contained in the certificate, in the form of an OR'ed flag set. |
- certKeyValid | Returns True if the certificate's key is cryptographically valid, and False otherwise. |
- certOCSPLocations | Locations of OCSP (Online Certificate Status Protocol) services that can be used to check this certificate's validity, as recorded by the CA. |
- certOrigin | Returns the origin of this certificate. |
- certPolicyIDs | Contains identifiers (OIDs) of the applicable certificate policies. |
- certPrivateKeyBytes | Contains the certificate's private key. |
- certPrivateKeyExists | Indicates whether the certificate has an associated private key. |
- certPrivateKeyExtractable | Indicates whether the private key is extractable. |
- certPublicKeyBytes | Contains the certificate's public key in DER format. |
- certSelfSigned | Indicates whether the certificate is self-signed (root) or signed by an external CA. |
- certSerialNumber | Returns the certificate's serial number. |
- certSigAlgorithm | Indicates the algorithm that was used by the CA to sign this certificate. |
- certSubject | The common name of the certificate holder, typically an individual's name, a URL, an e-mail address, or a company name. |
- certSubjectKeyID | Contains a unique identifier (fingerprint) of the certificate's private key. |
- certSubjectRDN | A collection of information, in the form of [OID, Value] pairs, uniquely identifying the certificate holder (subject). |
- certValidFrom | The time point at which the certificate becomes valid, in UTC. |
- certValidTo | The time point at which the certificate expires, in UTC. |
- certRequestBytes | Provides access to raw certificate request data in DER format. |
- certRequestCurve | Specifies the elliptic curve of the EC public key. |
- certRequestHandle | Allows to get or set a 'handle', a unique identifier of the underlying property object. |
- certRequestHashAlgorithm | Specifies the hash algorithm to be used in the operations on the certificate request (such as signing). |
- certRequestKeyAlgorithm | Specifies the public key algorithm of this certificate request. |
- certRequestKeyBits | Returns the length of the public key. |
- certRequestKeyUsage | Indicates the purposes of the key contained in the certificate request, in the form of an OR'ed flag set. |
- certRequestKeyValid | Returns True if the certificate's key is cryptographically valid, and False otherwise. |
- certRequestPrivateKeyBytes | Contains the certificate's private key. |
- certRequestPublicKeyBytes | Contains the public key incorporated in the request, in DER format. |
- certRequestSigAlgorithm | Indicates the algorithm that was used by the requestor to sign this certificate request. |
- certRequestSubject | The common name of the certificate holder, typically an individual's name, a URL, an e-mail address, or a company name. |
- certRequestSubjectRDN | A collection of information, in the form of [OID, Value] pairs, uniquely identifying the certificate holder (subject). |
- certRequestValid | Indicates whether or not the signature on the request is valid and matches the public key contained in the request. |
- externalCryptoCustomParams | Custom parameters to be passed to the signing service (uninterpreted). |
- externalCryptoData | Additional data to be included in the async state and mirrored back by the requestor. |
- externalCryptoExternalHashCalculation | Specifies whether the message hash is to be calculated at the external endpoint. |
- externalCryptoHashAlgorithm | Specifies the request's signature hash algorithm. |
- externalCryptoKeyID | The ID of the pre-shared key used for DC request authentication. |
- externalCryptoKeySecret | The pre-shared key used for DC request authentication. |
- externalCryptoMethod | Specifies the asynchronous signing method. |
- externalCryptoMode | Specifies the external cryptography mode. |
- externalCryptoPublicKeyAlgorithm | Provide public key algorithm here if the certificate is not available on the pre-signing stage. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
- config | Sets or retrieves a configuration setting. |
- download | Downloads a certificate from a remote location. |
- exportCert | Exports the certificate in the chosen format. |
- exportCSR | Exports a Certificate Signing Request (CSR). |
- exportKey | Exports the certificate's private key. |
- exportKeyToFile | Exports the private key to a file in the chosen format. |
- exportToFile | Exports the certificate to a file. |
- generate | Generates a new certificate. |
- generateAsyncBegin | Initiates asynchronous (DC) certificate generation. |
- generateAsyncEnd | Completes asynchronous certificate generation. |
- generateCSR | Creates a new certificate signing request (CSR). |
- generateExternal | Generates a new certificate with an external signing device. |
- getSampleCert | Generates a sample certificate for the specified purpose. |
- importCert | Imports a certificate. |
- importFromFile | Loads a certificate from a file. |
- importKey | Imports a private key. |
- importKeyFromFile | Imports a private key from a file. |
- update | Renews the certificate. |
- validate | Validates the certificate. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
- onError | Information about errors during certificate loading, saving or validation. |
- onExternalSign | Handles remote or external signing initiated by the SignExternal method or other source. |
- onNotification | This event notifies the application about an underlying control flow event. |
- onPasswordNeeded | This event is fired when a decryption password is needed. |
Configuration Settings
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
KeyExchangePIN | The KeyExchange PIN to provide to the key in runtime. |
SignaturePIN | The Signature PIN to provide to the key in runtime. |
TempPath | Path for storing temporary files. |
CheckKeyIntegrityBeforeUse | Enables or disable private key integrity check before use. |
CookieCaching | Specifies whether a cookie cache should be used for HTTP(S) transports. |
Cookies | Gets or sets local cookies for the class (supported for HTTPClient, RESTClient and SOAPClient only). |
DefDeriveKeyIterations | Specifies the default key derivation algorithm iteration count. |
EnableClientSideSSLFFDHE | Enables or disables finite field DHE key exchange support in TLS clients. |
GlobalCookies | Gets or sets global cookies for all the HTTP transports. |
HttpUserAgent | Specifies the user agent name to be used by all HTTP clients. |
LogDestination | Specifies the debug log destination. |
LogDetails | Specifies the debug log details to dump. |
LogFile | Specifies the debug log filename. |
LogFilters | Specifies the debug log filters. |
LogFlushMode | Specifies the log flush mode. |
LogLevel | Specifies the debug log level. |
LogMaxEventCount | Specifies the maximum number of events to cache before further action is taken. |
LogRotationMode | Specifies the log rotation mode. |
MaxASN1BufferLength | Specifies the maximal allowed length for ASN.1 primitive tag data. |
MaxASN1TreeDepth | Specifies the maximal depth for processed ASN.1 trees. |
OCSPHashAlgorithm | Specifies the hash algorithm to be used to identify certificates in OCSP requests. |
UseOwnDNSResolver | Specifies whether the client classes should use own DNS resolver. |
UseSharedSystemStorages | Specifies whether the validation engine should use a global per-process copy of the system certificate stores. |
UseSystemOAEPAndPSS | Enforces or disables the use of system-driven RSA OAEP and PSS computations. |
UseSystemRandom | Enables or disables the use of the OS PRNG. |