DFSEC_CertificateFromString¶
Include: Use System\Security.pkg
See Also: Certificates, DFSEC_CertificateFromFile, DFSEC_CertificateFree, DFSEC_Decode
Purpose¶
Creates a certificate handle from certificate data already held in DataFlex strings.
Syntax¶
Function DFSEC_CertificateFromString Global DFSEC_CERTFORMAT eFormat String sCertificate String sOptKey String sOptPassword Returns Handle
Arguments¶
eFormat
: Certificate format. Use C_DFSEC_CERTFORMAT_PEM or C_DFSEC_CERTFORMAT_P12.
sCertificate
: Certificate data. For PEM, pass PEM text. For P12, pass the certificate bundle bytes.
sOptKey
: Optional private key data. For PEM certificates, this may contain the private key. For P12 data, this is normally empty.
sOptPassword
: Optional password. For PEM certificates, this may unlock the private key. For P12 data, this may unlock the bundle.
Returns¶
A nonzero certificate handle on success, or 0 when no certificate handle could be created.
Behavior¶
DFSEC_CertificateFromString mirrors DFSEC_CertificateFromFile, but sCertificate and sOptKey contain the certificate and key data directly.
It returns 0 for an unsupported format, empty certificate data, invalid certificate data, a password/key mismatch, or an unsupported platform.
For a base64-encoded P12 value, decode the base64 text before passing the P12 data.
Example¶
String sP12Base64 sP12Data
Handle hCertificate
Move "...base64 p12 data..." to sP12Base64
Get DFSEC_Decode C_DFSEC_ENCODING_BASE64 sP12Base64 to sP12Data
Get DFSEC_CertificateFromString C_DFSEC_CERTFORMAT_P12 sP12Data "" "secret" to hCertificate
If (hCertificate <> 0) Begin
// Assign hCertificate to a consumer here.
Send DFSEC_CertificateFree hCertificate
End