CryptoSys PKI Pro
23.0.0
|
The C/C++ interface to the diCrPKI library. More...
Functions | |
long | ASN1_TextDump (const char *szFileOut, const char *szFileOrPEMString, long nOptions) |
Dumps details of ASN.1 formatted data to a text file. More... | |
long | ASN1_TextDumpToString (char *szOutput, long nOutChars, const char *szFileOrPEMString, const char *szDirName, long nOptions) |
Dumps details of ASN.1 formatted data to a string. More... | |
long | ASN1_Type (char *szOutput, long nOutChars, const char *szFileOrPEMString, long nOptions) |
Describes the type of ASN.1 data. More... | |
long | CIPHER_Bytes (long fEncrypt, unsigned char *lpOutput, const unsigned char *lpData, long nDataLen, const unsigned char *lpKey, const unsigned char *lpIV, const char *szAlgAndMode, long nOptions) |
Encrypt or decrypt data in a byte array. More... | |
long | CIPHER_DecryptAEAD (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const unsigned char *lpAAD, long nAadLen, long nOptions) |
Decrypt data using an authenticated encryption algorithm. More... | |
long | CIPHER_DecryptBytes (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions) |
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding. More... | |
long | CIPHER_DecryptHex (char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex, const char *szIvHex, const char *szAlgModePad, long nOptions) |
Decrypt data using the specified block cipher algorithm, mode and padding. More... | |
long | CIPHER_EncryptAEAD (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const unsigned char *lpAAD, long nAadLen, long nOptions) |
Encrypt data using an authenticated encryption algorithm. More... | |
long | CIPHER_EncryptBytes (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions) |
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding. More... | |
long | CIPHER_EncryptHex (char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex, const char *szIvHex, const char *szAlgModePad, long nOptions) |
Encrypt data using the specified block cipher algorithm, mode and padding. More... | |
long | CIPHER_File (long fEncrypt, const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, const unsigned char *lpIV, const char *szAlgAndMode, long nOptions) |
Encrypt or decrypt data in a file using the specified block cipher algorithm and mode. More... | |
long | CIPHER_FileDecrypt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions) |
Decrypt a file using specified block cipher algorithm, mode and padding. More... | |
long | CIPHER_FileEncrypt (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, const char *szAlgModePad, long nOptions) |
Encrypt a file using specified block cipher algorithm, mode and padding. More... | |
long | CIPHER_Hex (long fEncrypt, char *szOutput, long nOutChars, const char *szData, const char *szKey, const char *szIV, const char *szAlgAndMode, long nOptions) |
Encrypt or decrypt data represented as a hexadecimal string. More... | |
long | CIPHER_KeyUnwrap (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpData, long nDataLen, const unsigned char *lpKek, long nKekLen, long nOptions) |
Unwrap (decrypt) a content-encryption key with a key-encryption key. More... | |
long | CIPHER_KeyWrap (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpData, long nDataLen, const unsigned char *lpKek, long nKekLen, long nOptions) |
Wrap a content-encryption key with a key-encryption key. More... | |
long | CMS_GetSigDataDigest (char *szOutput, long nOutChars, const char *szFileIn, const char *szCertFile, long nOptions) |
Extracts the message digest from a signed-data CMS object file and verifies the signature. More... | |
long | CMS_MakeComprData (const char *szFileOut, const char *szFileIn, long nOptions) |
Creates a new CMS compressed-data file (.p7z) from an existing input file. More... | |
long | CMS_MakeDetachedSig (const char *szFileOut, const char *szHexDigest, const char *szCertList, const char *szPrivateKey, long nOptions) |
Creates a "detached signature" CMS signed-data object from a message digest of the content. More... | |
long | CMS_MakeEnvData (const char *szFileOut, const char *szFileIn, const char *szCertList, const char *szKeyString, long nCount, long nOptions) |
Create a CMS enveloped-data object for one or more recipients. More... | |
long | CMS_MakeEnvDataFromBytes (const char *szFileOut, const unsigned char *lpInput, long nInputLen, const char *szCertList, const char *szKeyString, long nCount, long nOptions) |
Create a CMS enveloped-data object from data in a byte array. More... | |
long | CMS_MakeEnvDataFromString (const char *szFileOut, const char *szDataIn, const char *szCertList, const char *szKeyString, long nCount, long nOptions) |
Create a CMS enveloped-data object from an ASCII string. More... | |
long | CMS_MakeSigData (const char *szFileOut, const char *szFileIn, const char *szCertList, const char *szPrivateKey, long nOptions) |
Creates a CMS object of type SignedData from an input data file. More... | |
long | CMS_MakeSigDataFromBytes (const char *szFileOut, const unsigned char *lpInput, long nInputLen, const char *szCertList, const char *szPrivateKey, long nOptions) |
Create a CMS object of type SignedData from an array of bytes. More... | |
long | CMS_MakeSigDataFromSigValue (const char *szFileOut, const unsigned char *lpSigValue, long nSigLen, const unsigned char *lpData, long nDataLen, const char *szCertList, long nOptions) |
Creates a CMS object of type SignedData using a pre-computed signature value. More... | |
long | CMS_MakeSigDataFromString (const char *szFileOut, const char *szDataIn, const char *szCertList, const char *szPrivateKey, long nOptions) |
Create a CMS object of type SignedData from an input string. More... | |
long | CMS_QueryEnvData (char *szOutput, long nOutChars, const char *szFileIn, const char *szQuery, long nOptions) |
Queries a CMS enveloped-data object file for selected information. More... | |
long | CMS_QuerySigData (char *szOutput, long nOutChars, const char *szFileIn, const char *szQuery, long nOptions) |
Queries a CMS signed-data object file for selected information. More... | |
long | CMS_ReadComprData (const char *szFileOut, const char *szFileIn, long nOptions) |
Read and extract the decompressed contents of a CMS compressed-data file. More... | |
long | CMS_ReadEnvData (const char *szFileOut, const char *szFileIn, const char *szCertFile, const char *szPrivateKey, long nOptions) |
Read and decrypt a CMS enveloped-data object to a file. More... | |
long | CMS_ReadEnvDataToBytes (unsigned char *lpOutput, long nOutBytes, const char *szFileIn, const char *szCertFile, const char *szPrivateKey, long nOptions) |
Reads and decrypts CMS enveloped-data object using the recipient's private key writing the plaintext data directly into a byte array. More... | |
long | CMS_ReadEnvDataToString (char *szOutput, long nOutChars, const char *szFileIn, const char *szCertFile, const char *szPrivateKey, long nOptions) |
Reads and decrypts CMS enveloped-data object using the recipient's private key writing the plaintext data directly into a string. More... | |
long | CMS_ReadSigData (const char *szFileOut, const char *szFileIn, long nOptions) |
Reads the content from a CMS signed-data object file. More... | |
long | CMS_ReadSigDataToBytes (unsigned char *lpOutput, long nOutBytes, const char *szFileIn, long nOptions) |
Reads the content from a CMS signed-data object file directly into a byte array. More... | |
long | CMS_ReadSigDataToString (char *szOutput, long nOutChars, const char *szFileIn, long nOptions) |
Reads the content from a CMS signed-data object file directly into a string. More... | |
long | CMS_VerifySigData (const char *szFileIn, const char *szCertFile, const char *szHexDigest, long nOptions) |
Verifies the signature and content of a signed-data CMS object file. More... | |
long | CNV_B64Filter (char *szOutput, const char *szInput, long nStrLen) |
Removes non-base64 characters from a string. More... | |
long | CNV_B64StrFromBytes (char *szOutput, long nOutChars, const unsigned char *lpInput, long nInputLen) |
Encodes an array of bytes into a base64-encoded string. More... | |
long | CNV_Base58FromBytes (char *szOutput, long nOutChars, const unsigned char *lpInput, long nInputLen) |
Encodes an array of bytes into a base58-encoded string. More... | |
long | CNV_Base58ToBytes (unsigned char *lpOutput, long nOutBytes, const char *szInput) |
Decodes a base58-encoded string into an array of bytes. More... | |
long | CNV_ByteEncoding (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nBytes, long nOptions) |
Converts encoding of byte array between UTF-8 and Latin-1. More... | |
long | CNV_BytesFromB64Str (unsigned char *lpOutput, long nOutBytes, const char *szInput) |
Decodes a base64-encoded string into an array of Bytes. More... | |
long | CNV_BytesFromHexStr (unsigned char *lpOutput, long nOutBytes, const char *szInput) |
Decodes a hexadecimal-encoded string into an array of Bytes. More... | |
long | CNV_CheckUTF8 (const char *szInput) |
Checks if a string only contains valid UTF-8 characters. More... | |
long | CNV_CheckUTF8Bytes (const unsigned char *lpInput, long nBytes) |
Checks if a byte array contains valid UTF-8 characters. More... | |
long | CNV_CheckUTF8File (const char *szFileName) |
Checks if a file contains valid UTF-8 characters. More... | |
long | CNV_HexFilter (char *szOutput, const char *szInput, long nStrLen) |
Removes non-hexadecimal characters from a string. More... | |
long | CNV_HexStrFromBytes (char *szOutput, long nOutChars, const unsigned char *lpInput, long nInputLen) |
Encodes an array of bytes into a hexadecimal-encoded string. More... | |
long | CNV_Latin1FromUTF8 (char *szOutput, long nOutChars, const char *szInput) |
Converts a UTF-8 string into a Latin-1 string, if possible. More... | |
long | CNV_Latin1FromUTF8Bytes (char *szOutput, long nOutChars, const unsigned char *lpInput, long nBytes) |
Converts UTF-8 encoded array of bytes into a Latin-1 string, if possible. More... | |
long | CNV_NumFromBytes (const unsigned char *lpInput, long nBytes, long nOptions) |
Converts the leftmost four bytes of an array to a 32-bit integer. More... | |
long | CNV_NumToBytes (unsigned char *lpOutput, long nOutBytes, long nNumber, long nOptions) |
Converts a 32-bit integer to an array of 4 bytes. More... | |
long | CNV_ReverseBytes (unsigned char *lpOutput, const unsigned char *lpInput, long nBytes) |
Reverses the order of a byte array. More... | |
long | CNV_ShortPathName (char *szOut, long nOutChars, const wchar_t *szwFilePath) |
Retrieve the Windows short path form of the specified path. More... | |
long | CNV_UTF8BytesFromLatin1 (unsigned char *lpOutput, long nOutBytes, const char *szInput) |
Converts a string of 8-bit Latin-1 characters into a UTF-8 encoded array of bytes. More... | |
long | CNV_UTF8FromLatin1 (char *szOutput, long nOutChars, const char *szInput) |
Converts a string of 8-bit Latin-1 characters into UTF-8 format. More... | |
long | CNV_Utf8FromWide (char *szOut, long nOutChars, const wchar_t *wstr) |
Maps a UTF-16 (wide character) string to a UTF-8-encoded string. More... | |
long | COMPR_Compress (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nOptions) |
Compress data using zlib compression. More... | |
long | COMPR_Uncompress (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nOptions) |
Uncompress data using zlib compression. More... | |
long | ECC_DHSharedSecret (unsigned char *lpZZ, long nOutBytes, const char *szIntPrivateKey, const char *szIntPublicKey, long nOptions) |
Compute EC Diffie-Hellman (ECDH) shared secret. More... | |
long | ECC_KeyHashCode (const char *szKeyString) |
Computes the hash code of an "internal" ECC public or private key string. More... | |
long | ECC_MakeKeys (const char *szPubKeyFile, const char *szPriKeyFile, const char *szCurveName, const char *szPassword, const char *szParams, long nOptions) |
Generates an EC public/private key pair and saves as two key files. More... | |
long | ECC_PublicKeyFromPrivate (char *szOutput, long nOutChars, const char *szIntKeyString, long nOptions) |
Converts an internal EC private key string into an internal EC public key string. More... | |
long | ECC_QueryKey (char *szOutput, long nOutChars, const char *szIntKeyString, const char *szQuery, long nOptions) |
Queries an EC key string for selected information. More... | |
long | ECC_ReadKeyByCurve (char *szOutput, long nOutChars, const char *szHexKey, const char *szCurveName, long nOptions) |
Reads an EC key from its hexadecimal (base16) representation. More... | |
long | ECC_ReadPrivateKey (char *szOutput, long nOutChars, const char *szKeyFileOrString, const char *szPassword, long nOptions) |
Reads an EC private key from a file into an internal key string. More... | |
long | ECC_ReadPublicKey (char *szOutput, long nOutChars, const char *szKeyFileOrString, long nOptions) |
Reads an EC public key from a file into an internal key string. More... | |
long | ECC_SaveEncKey (const char *szFileOut, const char *szIntKeyString, const char *szPassword, const char *szParams, long nOptions) |
Saves an internal EC private key string to an encrypted private key file. More... | |
long | ECC_SaveKey (const char *szFileOut, const char *szIntKeyString, long nOptions) |
Saves an internal EC key string to an unencrypted key file. More... | |
long | HASH_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, long nOptions) |
Creates a message digest hash as a byte array from byte data. More... | |
long | HASH_File (unsigned char *lpOutput, long nOutBytes, const char *szFileName, long nOptions) |
Creates a message digest hash in byte format for a file. More... | |
long | HASH_HexFromBytes (char *szOutput, long nOutChars, const void *lpMessage, long nMsgLen, long nOptions) |
Creates a message digest hash in hexadecimal format from byte (or string) data. More... | |
long | HASH_HexFromFile (char *szOutput, long nOutChars, const char *szFileName, long nOptions) |
Creates a message digest hash in hexadecimal format for a file. More... | |
long | HASH_HexFromHex (char *szOutput, long nOutChars, const char *szMsgHex, long nOptions) |
Creates a message digest hash in hexadecimal format from data in a hexadecimal-encoded string. More... | |
long | HASH_Length (long nAlgId) |
Return length of message digest output in bytes. More... | |
long | HMAC_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, const void *lpKey, long nKeyLen, long nOptions) |
Creates a keyed-hash based message authentication code (HMAC) as a byte array from byte data. More... | |
long | HMAC_HexFromBytes (char *szOutput, long nOutChars, const void *lpMessage, long nMsgLen, const void *lpKey, long nKeyLen, long nOptions) |
Creates a keyed-hash based message authentication code (HMAC) in hexadecimal format from byte data. More... | |
long | HMAC_HexFromHex (char *szOutput, long nOutChars, const char *szMsgHex, const char *szKeyHex, long nOptions) |
Creates a keyed-hash based message authentication code (HMAC) in hexadecimal format from data in hexadecimal-encoded strings. More... | |
long | HPKE_DerivePrivateKey (char *szOutput, long nOutChars, const unsigned char *lpIkm, long nIkmLen, const char *szCurveName, const char *szParams, long nOptions) |
Derive an EC private key in a deterministic manner from input keying material using the DeriveKeyPair algorithm in RFC9180. More... | |
long | HPKE_LabeledExpand (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpPrk, long nPrkLen, const char *szLabel, const unsigned char *lpInfo, long nInfoLen, const char *szCurveName, const char *szParams, long nOptions) |
Compute the output of the LabeledExpand function as defined in RFC9180. More... | |
long | HPKE_LabeledExtract (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpSalt, long nSaltLen, const char *szLabel, const unsigned char *lpIkm, long nIkmLen, const char *szCurveName, const char *szParams, long nOptions) |
Compute the output of the LabeledExtract function as defined in RFC9180. More... | |
long | KDF_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpIKM, long nIkmLen, const void *lpInfo, long nInfoLen, const char *szParams, long nOptions) |
Generate a key-encryption key (KEK) from input keying material using a key derivation function (KDF). More... | |
long | KDF_ForCms (unsigned char *lpOutput, long nOutBytes, const void *lpZZ, long nZzLen, const void *lpUkm, long nUkmLen, const char *szParams, long nOptions) |
Generate a key-encryption key (KEK) for ECDH key exchange in a CMS EnvelopedData object. More... | |
long | OCSP_MakeRequest (char *szOutput, long nOutChars, const char *szIssuerCert, const char *szCertFileOrSerialNum, const char *szExtensions, long nOptions) |
Creates an Online Certification Status Protocol (OCSP) request as a base64 string. More... | |
long | OCSP_ReadResponse (char *szOutput, long nOutChars, const char *szResponseFile, const char *szIssuerCert, const char *szExtensions, long nOptions) |
Reads a response to an Online Certification Status Protocol (OCSP) request and outputs the main results in text form. More... | |
long | PAD_BytesBlock (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nBlkLen, long nOptions) |
Creates an input block suitably padded for encryption by a block cipher in ECB or CBC mode. More... | |
long | PAD_HexBlock (char *szOutput, long nOutChars, const char *szInput, long nBlkLen, long nOptions) |
Creates a hex-encoded input block suitably padded for encryption by a block cipher in ECB or CBC mode. More... | |
long | PAD_UnpadBytes (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nBlkLen, long nOptions) |
Removes the padding from an encryption block. More... | |
long | PAD_UnpadHex (char *szOutput, long nOutChars, const char *szInput, long nBlkLen, long nOptions) |
Removes the padding from a hex-encoded encryption block. More... | |
long | PBE_Kdf2 (unsigned char *lpOutput, long nOutputLen, const unsigned char *lpPwd, long nPwdLen, const unsigned char *lpSalt, long nSaltLen, long nCount, long nOptions) |
Derives a key of any length from a password using the PBKDF2 algorithm from PKCS #5. More... | |
long | PBE_Kdf2Hex (char *szOutput, long nMaxChars, long dkBytes, const char *szPwd, const char *szSaltHex, long nCount, long nOptions) |
Derives a key of any length from a password using the PBKDF2 algorithm from PKCS #5 with the salt and output derived key encoded in hexadecimal. More... | |
long | PBE_Scrypt (unsigned char *lpDerivedKey, long nKeyLen, const unsigned char *lpPwd, long nPwdLen, const unsigned char *lpSalt, long nSaltLen, long nParamN, long nParamR, long nParamP, long nOptions) |
Derives a key of any length from a password using the SCRYPT algorithm. More... | |
long | PBE_ScryptHex (char *szOutput, long nMaxChars, long dkBytes, const char *szPwd, const char *szSaltHex, long nParamN, long nParamR, long nParamP, long nOptions) |
Derives a key of any length from a password using the SCRYPT algorithm with the salt and derived key encoded in hexadecimal. More... | |
long | PEM_FileFromBinFile (const char *szFileOut, const char *szFileIn, const char *szHeader, long nLineLen) |
Creates a PEM file from a binary file . More... | |
long | PEM_FileFromBinFileEx (const char *szFileOut, const char *szFileIn, const char *szHeader, long nLineLen, long nOptions) |
Creates a PEM file from a binary file with extended options. More... | |
long | PEM_FileToBinFile (const char *szFileOut, const char *szFileIn) |
Converts the contents of a PEM file into a binary file. More... | |
long | PFX_MakeFile (const char *szFileOut, const char *szCertList, const char *szEpkFile, const char *szPassword, const char *szFriendlyName, long nOptions) |
Creates a simple PFX (PKCS-12) file from an X.509 certificate and (optional) encrypted private key file. More... | |
long | PFX_VerifySig (const char *szFileName, const char *szPassword, long nOptions) |
Verifies the signature in a pkcs-12 file. More... | |
long | PKI_CompileTime (char *szOutput, long nOutChars) |
Retrieves the date and time the toolkit executable was last compiled. More... | |
long | PKI_ErrorCode (void) |
Returns the error code of the first error that occurred when calling the last function. More... | |
long | PKI_ErrorLookup (char *szOutput, long nOutChars, long nErrCode) |
Retrieves the error message associated with a given error code. More... | |
long | PKI_FormatErrorMessage (char *szOutput, long nOutChars, long nErrCode, const char *szUserMsg) |
Return a formatted error message string for the last error. More... | |
long | PKI_LastError (char *szOutput, long nOutChars) |
Retrieves the last error message set by the toolkit. More... | |
long | PKI_LicenceType (long nOptions) |
Returns the ASCII value of the licence type. More... | |
long | PKI_ModuleInfo (char *szOutput, long nOutChars, long nOptions) |
Get additional information about the core DLL module. More... | |
long | PKI_ModuleName (char *szOutput, long nOutChars, long nOptions) |
Retrieves the name of the current process's module. More... | |
long | PKI_Platform (char *szOutput, long nOutChars) |
Gets the platform the core DLL was compiled for. More... | |
long | PKI_PowerUpTests (long nOptions) |
Carries out on demand the full set of power-up tests automatically performed by the toolkit when first powered up (i.e. More... | |
long | PKI_Version (void *nReserved1, void *nReserved2) |
Retrieves the release version number. More... | |
long | PRF_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, const void *lpKey, long nKeyLen, const char *szCustom, long nOptions) |
Generate output bytes using a pseudorandom function (PRF). More... | |
long | PWD_Prompt (char *szPassword, long nPwdLen, const char *szCaption) |
Prompts for a password in a dialog box. More... | |
long | PWD_PromptEx (char *szPassword, long nPwdLen, const char *szCaption, const char *szPrompt, long nOptions) |
Prompts for a password in a dialog box with option to change prompt wording. More... | |
long | RNG_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpSeed, long nSeedLen) |
Generates a random set of byte data suitable for cryptographic keys. More... | |
long | RNG_BytesWithPrompt (unsigned char *lpOutput, long nOutBytes, const char *szPrompt, long nOptions) |
Generates a random set of byte data suitable for cryptographic keys with a prompt for the user to enter random keystrokes and mouse movements. More... | |
long | RNG_Guid (char *szOutput, long nOutChars, long nOptions) |
Generate a random 36-character Global Unique IDentifier (GUID) string. More... | |
long | RNG_Initialize (const char *szSeedFile, long nOptions) |
Initializes the RNG generator with a seed file. More... | |
long | RNG_MakeSeedFile (const char *szSeedFile, const char *szPrompt, long nOptions) |
Creates a new seed file suitable for use with RNG_Initialize(). More... | |
long | RNG_Number (long nLower, long nUpper) |
Returns an integer selected at random between specified limits. More... | |
long | RNG_Test (const char *szFileOut, long nOptions) |
Carries out a NIST SP800-90 health check and FIPS140-2 statistical tests on the random number generator. More... | |
long | RNG_TestDRBGVS (char *szOutput, long nMaxChars, long nReturnedBitsLen, const char *szEntropyInput, const char *szNonce, const char *szPersonalizationString, const char *szAdditionalInput1, const char *szEntropyReseed, const char *szAdditionalInputReseed, const char *szAdditionalInput2, long nOptions) |
Test the RNG for conformance to NIST SP800-90A using the relevant test specified in DRBGVS. More... | |
long | RNG_UpdateSeedFile (const char *szSeedFile, long nOptions) |
Updates an RNG seed file. More... | |
long | RSA_CheckKey (const char *szKeyString, long nOptions) |
Checks if an RSA key is valid. More... | |
long | RSA_DecodeMsg (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nOptions) |
Decodes an EME or EMSA encoded message block according to PKCS#1 (EME = Encoding Method for Encryption, EMSA = Encoding Method for Signature with Appendix). More... | |
long | RSA_Decrypt (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const char *szPrivateKeyFile, const char *szPassword, const char *szParameters, long nOptions) |
Decrypt a message encrypted using an RSA encryption scheme. More... | |
long | RSA_EncodeMsg (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, long nOptions) |
Creates an EME or EMSA encoded message block according to PKCS#1 (EME = Encoding Method for Encryption, EMSA = Encoding Method for Signature with Appendix). More... | |
long | RSA_Encrypt (unsigned char *lpOutput, long nOutBytes, const unsigned char *lpInput, long nInputLen, const char *szPublicKeyFile, const char *szParameters, long nOptions) |
Encrypt a short message using RSA encryption. More... | |
long | RSA_FromXMLString (char *szOutput, long nOutChars, const char *szXmlString, long nOptions) |
Creates an RSA key string in internal format from an XML string. More... | |
long | RSA_GetPrivateKeyFromPFX (const char *szFileOut, const char *szPfxFile, long nOptions) |
Extracts an encrypted private key from a PKCS-12 PKCS8ShroudedKeyBag, saving the output directly as a new file. More... | |
long | RSA_GetPublicKeyFromCert (char *szOutput, long nOutChars, const char *szCertFile, long nOptions) |
Reads a public key from an X.509 certificate into an "internal" public key string. More... | |
long | RSA_KeyBits (const char *szKeyString) |
Returns the length of key in bits given the public or private key string. More... | |
long | RSA_KeyBytes (const char *szKeyString) |
Returns the length of key in complete bytes (octets) given the public or private key string. More... | |
long | RSA_KeyHashCode (const char *szKeyString) |
Computes the hash code of an "internal" RSA public or private key string. More... | |
long | RSA_KeyMatch (const char *szPrivateKey, const char *szPublicKey) |
Verifies that a pair of "internal" RSA private and public key strings are matched. More... | |
long | RSA_KeyValue (char *szOutput, long nOutChars, const char *szKeyString, const char *szFieldName, long nOptions) |
Extracts a base64-encoded RSA key value from internal key string. More... | |
long | RSA_MakeKeys (const char *szPubKeyFile, const char *szEpkFile, long nBits, long nExpFermat, long nTests, long nCount, const char *szPassword, const void *lpSeed, long nSeedLen, long nOptions) |
Generate an RSA key pair and save as two key files. More... | |
long | RSA_MakeKeysXtd (const char *szPubKeyFile, const char *szPriKeyFile, const char *szPassword, long nBits, long nExpFermat, const char *szParams, long nOptions) |
Generate an RSA key pair and save as two key files. More... | |
long | RSA_PublicKeyFromPrivate (char *szOutput, long nOutChars, const char *szKeyString, long nOptions) |
Converts an internal RSA private key string into an internal public key string. More... | |
long | RSA_RawPrivate (unsigned char *lpData, long nDataLen, const char *szPrivateKey, long nOptions) |
Transforms (that is, encrypts or decrypts) raw data using an RSA private key. More... | |
long | RSA_RawPublic (unsigned char *lpData, long nDataLen, const char *szPublicKey, long nOptions) |
Transforms (that is, encrypts or decrypts) raw data using an RSA public key. More... | |
long | RSA_ReadAnyPrivateKey (char *szOutput, long nOutChars, const char *szKeyFileOrString, const char *szPassword, long nOptions) |
Reads from a file or string containing a private key into an "internal" private key string. More... | |
long | RSA_ReadAnyPublicKey (char *szOutput, long nOutChars, const char *szKeyFileOrString, long nOptions) |
Reads from a file or string containing a public key into an "internal" public key string. More... | |
long | RSA_ReadEncPrivateKey (char *szOutput, long nOutChars, const char *szEpkFile, const char *szPassword, long nOptions) |
Reads from an encrypted PKCS#8 private key info file into an "internal" private key string. More... | |
long | RSA_ReadPrivateKeyFromPFX (char *szOutput, long nOutChars, const char *szPfxFile, const char *szPassword, long nOptions) |
Reads a private key directly from an encrypted PFX/PKCS-12 file into an "internal" private key string. More... | |
long | RSA_ReadPrivateKeyInfo (char *szOutput, long nOutChars, const char *szKeyFile, long nOptions) |
Reads from an (unencrypted) PKCS-8 private key info file into an "internal" private key string. More... | |
long | RSA_ReadPublicKey (char *szOutput, long nOutChars, const char *szPubKeyFile, long nOptions) |
Reads from an RSA public key file into an "internal" public key string. More... | |
long | RSA_SaveEncKey (const char *szFileOut, const char *szIntKeyString, const char *szPassword, const char *szParams, long nOptions) |
Save an internal RSA key string to an encrypted key file. More... | |
long | RSA_SaveEncPrivateKey (const char *szFileOut, const char *szKeyString, long nCount, const char *szPassword, long nOptions) |
Saves a private key string to a PKCS-8 encrypted private key info file. More... | |
long | RSA_SavePrivateKeyInfo (const char *szFileOut, const char *szKeyString, long nOptions) |
Saves a private key string to an (unencrypted) PKCS-8 private key info file. More... | |
long | RSA_SavePublicKey (const char *szFileOut, const char *szKeyString, long nOptions) |
Saves a public key string to PKCS-1 public key file. More... | |
long | RSA_ToXMLString (char *szOutput, long nOutChars, const char *szKeyString, long nOptions) |
Creates an XML string representation of an RSA internal key string. More... | |
long | RSA_ToXMLStringEx (char *szOutput, long nOutChars, const char *szKeyString, const char *szPrefix, long nOptions) |
Creates an XML string representation of an RSA internal key string with option to add a namespace prefix. More... | |
long | SIG_SignData (char *szOutput, long nOutChars, const unsigned char *lpData, long nDataLen, const char *szKeyFile, const char *szPassword, const char *szAlgName, long nOptions) |
Compute a signature value over data in a byte array. More... | |
long | SIG_SignFile (char *szOutput, long nOutChars, const char *szDataFile, const char *szKeyFile, const char *szPassword, const char *szAlgName, long nOptions) |
Compute a signature value over data in a file. More... | |
long | SIG_VerifyData (const char *szSignature, const unsigned char *lpData, long nDataLen, const char *szCertOrKeyFile, const char *szAlgName, long nOptions) |
Verify a signature value over data in a byte array. More... | |
long | SIG_VerifyFile (const char *szSignature, const char *szDataFile, const char *szCertOrKeyFile, const char *szAlgName, long nOptions) |
Verify a signature value over data in a file. More... | |
long | SMIME_Extract (const char *szFileOut, const char *szFileIn, long nOptions) |
Extract the body from an S/MIME entity. More... | |
long | SMIME_Query (char *szOutput, long nOutChars, const char *szFileIn, const char *szQuery, long nOptions) |
Query an S/MIME entity. More... | |
long | SMIME_Wrap (const char *szFileOut, const char *szFileIn, const char *szFeatures, long nOptions) |
Wrap a CMS object in an S/MIME entity. More... | |
long | TDEA_B64Mode (char *szOutput, const char *szInput, const char *szKey, long fEncrypt, const char *szMode, const char *szIV) |
Encrypts or decrypts data encoded in base64 using a specified mode. More... | |
long | TDEA_BytesMode (unsigned char *lpOutput, const unsigned char *lpData, long nDataLen, const unsigned char *lpKey, long fEncrypt, const char *szMode, const unsigned char *lpIV) |
Encrypts or decrypts an array of Bytes in one step using a specified mode. More... | |
long | TDEA_File (const char *szFileOut, const char *szFileIn, const unsigned char *lpKey, long fEncrypt, const char *szMode, const unsigned char *lpIV) |
Encrypts or decrypts a file using a specified mode. More... | |
long | TDEA_HexMode (char *szOutput, const char *szInput, const char *szKey, long fEncrypt, const char *szMode, const char *szIV) |
Encrypts or decrypts data represented as a hexadecimal string using a specified mode. More... | |
long | WIPE_Data (void *lpData, long nDataLen) |
Zeroise data in memory. More... | |
long | WIPE_File (const char *szFileName, long nOptions) |
Wipe and delete a file using secure 7-pass DOD standards. More... | |
long | X509_CertExpiresOn (const char *szCertFile, char *szOutput, long nOutChars, long nOptions) |
Returns the date and time an X.509 certificate expires. More... | |
long | X509_CertIssuedOn (const char *szCertFile, char *szOutput, long nOutChars, long nOptions) |
Returns the date and time an X.509 certificate was issued. More... | |
long | X509_CertIssuerName (const char *szCertFile, char *szOutput, long nOutChars, const char *szDelim, long nOptions) |
Extracts issuer's distinguished name from X.509 certificate. More... | |
long | X509_CertIsValidNow (const char *szCertFile, long nOptions) |
Verifies that an X.509 certificate is currently valid. More... | |
long | X509_CertRequest (const char *szNewReqFile, const char *szPriKeyFile, const char *szDistName, const char *szExtensions, const char *szPassword, long nOptions) |
Creates a PKCS #10 certificate signing request (CSR) using the subject's private key file. More... | |
long | X509_CertSerialNumber (const char *szCertFile, char *szOutput, long nOutChars, long nOptions) |
Returns the serial number of an X.509 certificate. More... | |
long | X509_CertSubjectName (const char *szCertFile, char *szOutput, long nOutChars, const char *szDelim, long nOptions) |
Extracts subject's distinguished name from X.509 certificate. More... | |
long | X509_CertThumb (const char *szCertFile, char *szOutput, long nOutChars, long nOptions) |
Calculates the thumbprint (message digest hash) of an X.509 certificate. More... | |
long | X509_CheckCertInCRL (const char *szCertFile, const char *szCrlFile, const char *szCRLIssuerCert, const char *szDate, long nOptions) |
Checks whether an X.509 certificate has been revoked in a Certificate Revocation List (CRL). More... | |
long | X509_GetCertCountInP7Chain (const char *szP7cFile, long nOptions) |
Return number of certificates in a PKCS-7 "certs-only" certificate chain file. More... | |
long | X509_GetCertFromP7Chain (const char *szNewCertFile, const char *szP7cFile, long nIndex, long nOptions) |
Extracts an X.509 certificate from a PKCS-7 "certs-only" certificate chain file (typically saved with extension .p7c or .p7b), saving the output directly as a new file. More... | |
long | X509_GetCertFromPFX (const char *szNewCertFile, const char *szPfxFile, const char *szPassword, long nOptions) |
Extracts an X.509 certificate from a PKCS-12 PFX/.p12 file, saving the output directly as a new file. More... | |
long | X509_HashIssuerAndSN (const char *szCertFile, char *szOutput, long nOutChars, long nOptions) |
Returns the message digest hash of the PKCS #7 issuerAndSerialNumber value of an X.509 certificate in hexadecimal format. More... | |
long | X509_KeyUsageFlags (const char *szCertFile) |
Returns a bitfield containing the keyUsage flags for an X.509 certificate. More... | |
long | X509_MakeCert (const char *szNewCertFile, const char *szIssuerCertFile, const char *szSubjectPubKeyFile, const char *szIssuerPriKeyFile, long nCertNum, long nYearsValid, const char *szDistName, const char *szExtensions, long nKeyUsageFlags, const char *szPassword, long nOptions) |
Creates an X.509 certificate using subject's public key and issuer's private key files. More... | |
long | X509_MakeCertSelf (const char *szNewCertFile, const char *szPriKeyFile, long nCertNum, long nYearsValid, const char *szDistName, const char *szExtensions, long nKeyUsageFlags, const char *szPassword, long nOptions) |
Creates a self-signed X.509 certificate. More... | |
long | X509_MakeCRL (const char *szCrlFile, const char *szIssuerCert, const char *szIssuerKeyFile, const char *szPassword, const char *szRevokedCertList, const char *szExtensions, long nOptions) |
Creates an X.509 Certificate Revocation List (CRL). More... | |
long | X509_QueryCert (char *szOutput, long nOutChars, const char *szCertFile, const char *szQuery, long nOptions) |
Queries an X.509 certificate file for selected information. More... | |
long | X509_ReadCertStringFromP7Chain (char *szOutput, long nOutChars, const char *szP7cFile, long nIndex, long nOptions) |
Reads an X.509 certificate into a base64 string from PKCS-7 "certs-only" data. More... | |
long | X509_ReadCertStringFromPFX (char *szOutput, long nOutChars, const char *szPfxFile, const char *szPassword, long nOptions) |
Reads an X.509 certificate into a base64 string from PKCS-12 PFX/.p12 data. More... | |
long | X509_ReadStringFromFile (char *szOutput, long nOutChars, const char *szCertFile, long nOptions) |
Creates a base64 string of an X.509 certificate file. More... | |
long | X509_SaveFileFromString (const char *szNewCertFile, const char *szCertString, long nOptions) |
Creates an X.509 certificate file from its base64 string representation. More... | |
long | X509_TextDump (const char *szFileOut, const char *szCertFile, long nOptions) |
Dumps details of an X.509 certificate (or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR)) to a text file. More... | |
long | X509_TextDumpToString (char *szOutput, long nOutChars, const char *szCertFile, long nOptions) |
Dumps details of an X.509 certificate or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR) to a string. More... | |
long | X509_ValidatePath (const char *szCertListOrP7File, const char *szTrustedCert, long nOptions) |
Validates a certificate path. More... | |
long | X509_VerifyCert (const char *szCertToVerify, const char *szIssuerCert, long nOptions) |
Verifies that an X.509 certificate - or X.509 certificate revocation list (CRL) or PKCS-10 certificate signing request (CSR) - has been signed by its issuer. More... | |
long | XOF_Bytes (unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, long nOptions) |
Generate bytes using an extendable output function (XOF). More... | |
The C/C++ interface to the diCrPKI library.
char
type for null-terminated strings, denoted szFoo
, and the unsigned char
for byte arrays, denoted lpBar
. Byte arrays must have their length specified in a separate variable, typically named nBarLen
. -----BEGIN CERTIFICATE----- MIHgMIGaAgEBMA0GCSqG... -----END CERTIFICATE-----
-----BEGIN CERTIFICATE----- MIHgMIGaAgEBMA0GCSqG... -----END CERTIFICATE-----Similarly, those RSA functions which require you to pass the filename of an RSA key file will accept a string that contains the file contents in PEM format. An RSA key file in PEM format looks like
-----BEGIN ENCRYPTED PRIVATE KEY----- MIICojAcBgoqhkiG9w0BDAEDMA4ECHPQz6NdAmoFAgIH0ASCAoBKn9KXr+dm Vtc0ZhEog7t3Prs4rJazwUsXExU78ePLMquxLi/cPmqtyjb472r6XUOa... -----END ENCRYPTED PRIVATE KEY-----The functions will accept all strings that start with
"-----BEGIN"
and are of the form -----BEGIN XXX----- (base64-encoded data) -----END XXX-----The exact word or words used for "XXX" do not matter, but there must be exactly 5 dash characters "-" before and after. Any non-base64 characters found in the encoded data, including newline characters or spaces, will be ignored.
0 = OK, success, no error (SUCCESS_NO_ERROR) 1 = Cannot open input file (OPEN_ERROR) 2 = Cannot create output file (CREATE_ERROR) 3 = File read error (READ_ERROR) 4 = File write error (WRITE_ERROR) 5 = Not enough memory (MEMORY_ERROR) 6 = Parameter is wrong or missing (BAD_PARAM_ERROR) 7 = Data in wrong format (BAD_FORMAT_ERROR) 8 = Invalid data (INVALID_DATA_ERROR) 9 = Unexpected end of file found (EOF_ERROR) 10 = Required data not found (MISSING_ERROR) 11 = Value out of range (OUT_OF_RANGE_ERROR) 12 = Duplicate data (DUP_ERROR) 13 = Misc file IO error (IO_ERROR) 14 = Unexpected NULL value (NULL_ERROR) 15 = Decryption error (DECRYPT_ERROR) 16 = Item has expired or is not yet valid (EXPIRED_ERROR) 17 = Invalid option (BAD_FLAG_ERROR) 18 = Failed to wipe data (WIPE_ERROR) 19 = Item is not supported (NOT_SUPPORTED_ERROR) 20 = No data found to process (NO_DATA_ERROR) 21 = No match found (NO_MATCH_ERROR) 22 = Signature is invalid (SIGNATURE_ERROR) 23 = Failed a test e.g. known answer test (TEST_FAILED_ERROR) 24 = Key generation failed (KEYGEN_FAILED_ERROR) 25 = Certificate issuer error (ISSUER_ERROR) 26 = Data not a valid length (BAD_LENGTH_ERROR) 27 = Invalid XML format (BAD_XML_ERROR) 29 = Not a valid query (BAD_QUERY_ERROR) 30 = Not enough room in output buffer (SHORT_BUF_ERROR) 31 = Zlib compression error (ZLIB_COMPR_ERROR) 33 = Invalid key length (BAD_KEY_LEN_ERROR) 34 = Invalid block length (BAD_BLK_LEN_ERROR) 35 = Invalid mode (BAD_MODE_ERROR) 36 = Invalid key (BAD_KEY_ERROR) 37 = Invalid initialization vector (BAD_IV_ERROR) 38 = Invalid IV length (BAD_IV_LEN_ERROR) 39 = Unable to encode (ENCODING_ERROR) 42 = Item has been revoked (REVOCATION_ERROR) 43 = Certificate path is invalid (CERT_PATH_ERROR) 201 = PRNG: Cannot open input file (PRNG_ERR_FILE_OPEN) 202 = PRNG: Cannot create output file (PRNG_ERR_FILE_CREATE) 203 = PRNG: File read error (PRNG_ERR_FILE_READ) 204 = PRNG: File write error (PRNG_ERR_FILE_WRITE) 205 = PRNG: File locking error (PRNG_ERR_FILE_LOCK) 210 = PRNG: Uninstantiation failed (PRNG_ERR_UNINST) 211 = PRNG: Requested length is too large (PRNG_ERR_TOOBIG) 212 = PRNG: Function failed (PRNG_ERR_FAILURE) 213 = PRNG: Invalid input parameter (PRNG_ERR_BADPARAM) 214 = PRNG: Function is not available (PRNG_ERR_NOTAVAIL) 299 = PRNG: Catastrophic failure (PRNG_ERR_CATASTROPHIC) 9745 = Something not expected to happen has happened (INTERNAL_ERROR) 9999 = Miscellaneous error (MISC_ERROR)To find the error message corresponding to a numerical error code use the PKI_ErrorLookup() function. Use PKI_ErrorCode() to find the error code that occurred when calling the last function. More details on the error can usually be found by using the PKI_LastError() function which outputs a description of the error or errors that have occurred. Be warned that not all errors set this description.
long ASN1_TextDump | ( | const char * | szFileOut, |
const char * | szFileOrPEMString, | ||
long | nOptions | ||
) |
Dumps details of ASN.1 formatted data to a text file.
[in] | szFileOut | filename of text file to be created. |
[in] | szFileOrPEMString | filename of ASN.1 formatted data file to be analyzed (or its base64 representation or PEM string). |
[in] | nOptions | option flags:PKI_ASN1_NOCOMMENTS to hide the commentsPKI_ASN1_ADDLEVELS to show level numbers |
Only data with an outer SEQUENCE is accepted, which is the rule for all common PKI-related ASN.1 files.
The output is a text file showing the structure of the ASN.1 formatted data. All the bytes in the input are printed in hexadecimal form laid out to show the nested structure of the ASN.1 formatted data together with comments beginning with "--"
that give further details about the elements. The length of each object is shown in bytes, for example
30 81 e0 --SEQUENCE/224 bytes
shows the tag (30
) and length bytes (81 e0
) which begin a SEQUENCE of length 224 bytes, equal to hexadecimal E0 bytes.
Use the PKI_ASN1_NOCOMMENTS
option to hide the comments: the resulting hexadecimal output without comments should decode back directly to the original binary file.
long ASN1_TextDumpToString | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileOrPEMString, | ||
const char * | szDirName, | ||
long | nOptions | ||
) |
Dumps details of ASN.1 formatted data to a string.
[out] | szOutput | String buffer to receive output. |
[in] | nOutChars | Maximum number of characters to be received. |
[in] | szFileOrPEMString | Filename of ASN.1 formatted data file to be analyzed (or its base64 representation or PEM string). |
[in] | szDirName | Directory in which to create a temporary file. Specify "" for default = system TEMP directory. |
[in] | nOptions | option flags:PKI_ASN1_NOCOMMENTS to hide the commentsPKI_ASN1_ADDLEVELS to show level numbers |
The input may be a binary file in BER/DER format or a text file in PEM or base64-encoded format, or may be passed as a base64 string or as a PEM string.
Only data with an outer SEQUENCE is accepted, which is the rule for all common PKI-related ASN.1 files.
The output is a text file showing the structure of the ASN.1 formatted data. All the bytes in the input are printed in hexadecimal form laid out to show the nested structure of the ASN.1 formatted data together with comments beginning with "--"
that give further details about the elements. The length of each object is shown in bytes, for example
30 81 e0 --SEQUENCE/224 bytes
shows the tag (30
) and length bytes (81 e0
) which begin a SEQUENCE of length 224 bytes, equal to hexadecimal E0 bytes.
Use the PKI_ASN1_NOCOMMENTS
option to hide the comments: the resulting hexadecimal output without comments should decode back directly to the original binary file.
This function creates a temporary file, by default in the system TEMP
directory. This file is locked and is automatically deleted after use. The user can specify a particular directory known to be secure if required. If the specified directory does not exist, the system TEMP
directory will be used.
long ASN1_Type | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileOrPEMString, | ||
long | nOptions | ||
) |
Describes the type of ASN.1 data.
[out] | szOutput | string of sufficient length to receive the output (guaranteed not to be longer than PKI_ASN1_TYPE_MAXCHARS ). |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szFileOrPEMString | filename of ASN.1 formatted data file to be analyzed (or its base64 representation or PEM string). |
[in] | nOptions | option flags: not used in this release. Specify zero. |
The input may be a binary file in BER/DER format or a text file in PEM or base64 format, or may be passed as a base64 string or as a PEM string. The output is a string describing the most likely type of the ASN.1-formatted data, or an empty string (""
) if the type cannot be determined. The following types are detected:
Output string value | ASN.1 object type | Reference |
---|---|---|
EC PRIVATE KEY | ECPrivateKey | [RFC5915] |
OCSP REQUEST | OCSPRequest | [RFC6960] |
OCSP RESPONSE | OCSPResponse | [RFC6960] |
PKCS1 RSA PRIVATE KEY | RSAPrivateKey | [RFC3447] |
PKCS1 RSA PUBLIC KEY | RSAPublicKey | [RFC3447] |
PKCS10 CERTIFICATE REQUEST | CertificationRequest | [RFC2986] |
PKCS12 PFX | PFX | [RFC7292] |
PKCS7 CERTIFICATE CHAIN | ContentInfo | [RFC5652] |
PKCS7/CMS COMPRESSED DATA | ContentInfo | [RFC3274] |
PKCS7/CMS DATA | ContentInfo | [RFC5652] |
PKCS7/CMS ENVELOPED DATA | ContentInfo | [RFC5652] |
CMS AUTH ENVELOPED DATA | ContentInfo | [RFC5083] |
PKCS7/CMS SIGNED DATA | ContentInfo | [RFC5652] |
PKCS8 ENCRYPTED PRIVATE KEY | EncryptedPrivateKeyInfo | [RFC5208], [RFC5958] |
PKCS8 PRIVATE KEY INFO | PrivateKeyInfo | [RFC5208], [RFC5958] |
PKCS8 ONE ASYMMETRIC KEY | OneAsymmetricKey | [RFC5958] |
PUBLIC KEY INFO | SubjectPublicKeyInfo | [RFC3279], [RFC5480] |
X509 CERTIFICATE | Certificate | [RFC5280] |
X509 CRL | CertificateList | [RFC5280] |
Note that these descriptions are not necessarily those used as labels for PEM formatted files. See PEM_FileFromBinFile and [RFC7468].
long CIPHER_Bytes | ( | long | fEncrypt, |
unsigned char * | lpOutput, | ||
const unsigned char * | lpData, | ||
long | nDataLen, | ||
const unsigned char * | lpKey, | ||
const unsigned char * | lpIV, | ||
const char * | szAlgAndMode, | ||
long | nOptions | ||
) |
Encrypt or decrypt data in a byte array.
The key and initialization vector are given as byte arrays.
[in] | fEncrypt | direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt. |
[out] | lpOutput | array of sufficient length to receive the output. |
[in] | lpData | array containing the input data. |
[in] | nDataLen | specifying the length of the input data in bytes. |
[in] | lpKey | array containing the key. |
[in] | lpIV | containing the initialization vector (IV), or zero (0) for ECB mode. |
[in] | szAlgAndMode | containing the block cipher algorithm and mode (see Specifying the algorithm and mode for generic block cipher functions). |
[in] | nOptions | option flags. |
The length of key lpKey must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.
Important: The output array lpOutput must be at least nDataLen bytes long. lpOutput and lpData may be the same.
For ECB and CBC modes, the length of the input data lpInput must be an exact multiple of the block size otherwise a BAD_LENGTH_ERROR
error will result. It is the responsibility of the user to provide suitable padding before encrypting in those modes and to remove any padding after decrypting.
long CIPHER_DecryptAEAD | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const unsigned char * | lpKey, | ||
long | nKeyLen, | ||
const unsigned char * | lpIV, | ||
long | nIvLen, | ||
const unsigned char * | lpAAD, | ||
long | nAadLen, | ||
long | nOptions | ||
) |
Decrypt data using an authenticated encryption algorithm.
[out] | lpOutput | array of sufficient length to receive the output. |
[in] | nOutBytes | length of the output buffer in bytes. |
[in] | lpInput | array containing the input data. |
[in] | nInputLen | length of the input data in bytes. |
[in] | lpKey | array containing the key. |
[in] | nKeyLen | length of the key in bytes. |
[in] | lpIV | initialization vector (IV), a.k.a. nonce, if not provided in input. |
[in] | nIvLen | length of the IV in bytes. |
[in] | lpAAD | additional authenticated data (AAD) |
[in] | nAadLen | length of the AAD in bytes. |
[in] | nOptions | option flags. Must be one of:PKI_AEAD_AES_128_GCM to use AEAD_AES_128_GCM authenticated encryption algorithm from RFC 5116PKI_AEAD_AES_256_GCM to use AEAD_AES_256_GCM authenticated encryption algorithm from RFC 5116PKI_AEAD_AES_192_GCM to use the AES-192-GCM authenticated encryption algorithm in the same mannerPKI_AEAD_CHACHA20_POLY1305 to use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm (RFC8439)and optionally add PKI_IV_PREFIX to expect the IV to be prepended at the start of the input. |
ciphertext||Tag
, or, if the PKI_IV_PREFIX
option is set, then the same but with the 12-byte IV prepended IV||ciphertext||Tag
, where ||
denotes concatenation. If the IV is not prepended to the input, then it must be provided in the lpIV argument. Note that the term "IV" is used here to mean exactly the same as "nonce".The length of key lpKey must be exactly the required key size in bytes: 16 for PKI_AEAD_AES_128_GCM
, 24 for PKI_AEAD_AES_192_GCM
, or 32 for PKI_AEAD_AES_256_GCM
. It is an error if a PKI_AEAD_
option is not provided in the nOptions argument. In all cases the IV must be exactly 12 bytes (96 bits) and the tag must be exactly 16 bytes (128 bits). If additional authentication data (AAD) was provided during encryption then the exact same AAD data must be provided here.
If nOutBytes is set to zero or lpOutput set to 0 (or NULL
in C or ByVal 0&
in VBA), the required number of bytes will be returned. This will be either exactly 16 bytes shorter than the length of the input, or exactly 28 bytes shorter if the PKI_IV_PREFIX
option is used.
The output buffer lpOutput must not be the same as or overlap with the input lpInput.
long CIPHER_DecryptBytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const unsigned char * | lpKey, | ||
long | nKeyLen, | ||
const unsigned char * | lpIV, | ||
long | nIvLen, | ||
const char * | szAlgModePad, | ||
long | nOptions | ||
) |
Decrypt data in a byte array using the specified block cipher algorithm, mode and padding.
The key and initialization vector are passed as byte arrays.
[out] | lpOutput | array of sufficient length to receive the output (must be at least as long as the input, see ** in remarks)). |
[in] | nOutBytes | specifying the length of the output buffer in bytes. |
[in] | lpInput | array containing the input data. |
[in] | nInputLen | specifying the length of the input data in bytes. |
[in] | lpKey | array containing the key. |
[in] | nKeyLen | the length of the key in bytes. |
[in] | lpIV | containing the initialization vector (IV), or zero (0) or NULL for ECB mode. |
[in] | nIvLen | the length of the IV in bytes. |
[in] | szAlgModePad | containing the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions). |
[in] | nOptions | option flags: Zero (0) for default options. Optionally add: PKI_IV_PREFIX to expect the IV to be prepended before the ciphertext in the input (ignored for ECB mode). |
The length of key lpKey must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.
[New in v12.3] You can find the required output length in bytes by setting nOutBytes to zero or lpOutput to 0 (or NULL
in C or ByVal 0&
in VBA). For ECB and CBC cipher modes, the return value is now (as of [v12.3]) the exact length of plaintext after padding has been removed.
** For ECB and CBC cipher modes, any padding must be removed. To specify the length of lpOutput you can either
NULL
to find the exact decrypted length. See the examples below. In both cases you may need to cope with the special case where the encrypted output is the empty string, a zero-length byte array.
It is an error (DECRYPT_ERROR
) if the padding bytes after decryption are not as expected according to the padding method specified. If the cipher mode is ECB or CBC, it is an error (BAD_LENGTH_ERROR
) if the length of the input is not an exact multiple of the block size. The input buffer lpInput may point to the same location as the output buffer. If so, the input ciphertext data will be overwritten by the output (and the user must truncate to remove any padding bytes).
Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding
will be used for ECB and CBC mode and nopadding
for all other modes. The default cipher mode is ECB
. Thus "aes128"
is the same as "aes128/ecb/pkcs5padding"
.
long CIPHER_DecryptHex | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szInputHex, | ||
const char * | szKeyHex, | ||
const char * | szIvHex, | ||
const char * | szAlgModePad, | ||
long | nOptions | ||
) |
Decrypt data using the specified block cipher algorithm, mode and padding.
The input data, key and initialization vector are all represented as hexadecimal strings.
[out] | szOutput | string buffer of sufficient length to receive the output. |
[in] | nOutChars | maximum number of characters to be received. |
[in] | szInputHex | the input data in hex format. |
[in] | szKeyHex | the key in hex format. |
[in] | szIvHex | the initialization vector (IV) in hex format, ignored for ECB mode or if PKI_IV_PREFIX is used (use "" ). |
[in] | szAlgModePad | string specifying the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions). |
[in] | nOptions | option flags: Zero (0) for default options. Optionally add: PKI_IV_PREFIX to expect the IV to be prepended before the ciphertext in the input (not applicable for ECB mode). |
This is the equivalent of CIPHER_DecryptBytes
with all parameters passed as hex-encoded strings instead of byte arrays. It is similar to the CIPHER_Hex
function except this accepts variable-length input and copes with padding if required, as well as the option to prepend the IV to the ciphertext.
Any padding will be removed after decryption.
If the PKI_IV_PREFIX
option is used, the IV will be expected prepended to the ciphertext in the input.
The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).
It is an error (BAD_PARAM_ERROR
) to pass the empty string ""
as input in szInputHex. The output buffer strOutput should not be the same as the input strInputHex.
CAUTION: be aware of the special case where the output is the empty string ""
of length zero.
long CIPHER_EncryptAEAD | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const unsigned char * | lpKey, | ||
long | nKeyLen, | ||
const unsigned char * | lpIV, | ||
long | nIvLen, | ||
const unsigned char * | lpAAD, | ||
long | nAadLen, | ||
long | nOptions | ||
) |
Encrypt data using an authenticated encryption algorithm.
[out] | lpOutput | array of sufficient length to receive the output. |
[in] | nOutBytes | length of the output buffer in bytes. |
[in] | lpInput | array containing the input data. |
[in] | nInputLen | length of the input data in bytes. |
[in] | lpKey | array containing the key. |
[in] | nKeyLen | length of the key in bytes. |
[in] | lpIV | (required) initialization vector (IV), a.k.a. nonce. |
[in] | nIvLen | length of the IV in bytes (must be exactly 12). |
[in] | lpAAD | (optional) additional authenticated data (AAD) |
[in] | nAadLen | length of the AAD in bytes. |
[in] | nOptions | option flags. Must be one of:PKI_AEAD_AES_128_GCM to use AEAD_AES_128_GCM authenticated encryption algorithm from RFC 5116PKI_AEAD_AES_256_GCM to use AEAD_AES_256_GCM authenticated encryption algorithm from RFC 5116PKI_AEAD_AES_192_GCM to use the AES-192-GCM authenticated encryption algorithm in the same mannerPKI_AEAD_CHACHA20_POLY1305 to use the AEAD_CHACHA20_POLY1305 authenticated encryption algorithm (RFC 8439)and optionally add PKI_IV_PREFIX to prepend the IV before the ciphertext in the output. |
PKI_IV_PREFIX
option flag. Note that the term "IV" is used here to mean exactly the same as "nonce".The length of key lpKey must be exactly the required key size in bytes: 16 for PKI_AEAD_AES_128_GCM
, 24 for PKI_AEAD_AES_192_GCM
, or 32 for PKI_AEAD_AES_256_GCM
. It is an error if a PKI_AEAD_
option is not provided in the nOptions argument. The length of the IV must be exactly 12 bytes. The user is responsible for providing a unique IV each time the same key is used. Be aware it is a serious security risk if the same IV and key are used to encrypt different plaintexts.
If nOutBytes is set to zero or lpOutput set to 0 (or NULL
in C or ByVal 0&
in VBA), the required number of bytes will be returned. This will be either exactly 16 bytes longer than the length of the input, or exactly 28 bytes longer if the PKI_IV_PREFIX
option is used.
The output buffer lpOutput must not be the same as or overlap with the input lpInput.
long CIPHER_EncryptBytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const unsigned char * | lpKey, | ||
long | nKeyLen, | ||
const unsigned char * | lpIV, | ||
long | nIvLen, | ||
const char * | szAlgModePad, | ||
long | nOptions | ||
) |
Encrypt data in a byte array using the specified block cipher algorithm, mode and padding.
The key and initialization vector are passed as byte arrays.
[out] | lpOutput | array of sufficient length to receive the output. |
[in] | nOutBytes | specifying the length of the output buffer in bytes. |
[in] | lpInput | array containing the input data. |
[in] | nInputLen | specifying the length of the input data in bytes. |
[in] | lpKey | array containing the key. |
[in] | nKeyLen | the length of the key in bytes. |
[in] | lpIV | containing the initialization vector (IV), or zero (0) or NULL for ECB mode. |
[in] | nIvLen | the length of the IV in bytes. |
[in] | szAlgModePad | containing the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions). |
[in] | nOptions | option flags: Zero (0) for default options. Optionally add: PKI_IV_PREFIX to prepend the IV before the ciphertext in the output (ignored for ECB mode). |
The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).
The length of key lpKey must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.
If nOutBytes is set to zero or lpOutput set to 0 (or NULL
in C or ByVal 0&
in VBA), the required number of bytes will be returned. If the NoPadding
option is specified, the required output length will be the same as the input.
Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding
will be used for ECB and CBC mode and nopadding
for all other modes. The default cipher mode is ECB
. Thus "aes128"
is the same as "aes128/ecb/pkcs5padding"
.
Note that padding is only needed for ECB or CBC mode where the input length is not a multiple of the block size. It is an error (BAD_LENGTH_ERROR
) to specify NoPadding
with ECB or CBC mode if the length of the input is not an exact multiple of the block size.
The padding option is ignored for CTR, OFB and CFB modes, which do not need padding. The default nopadding
is always used for these modes regardless of what is specified (so just use the default, e.g. "aes128/ctr"
).
[New in v12.3] Use the PKI_IV_PREFIX
to prepend the IV before the ciphertext in the output. This will add the IV before the ciphertext in the form IV||CT
. This is the scheme used with block ciphers in XML encryption (see section 5.2 of [XMLENC]) where they use the phrase "The resulting cipher text is prefixed by the IV." It is the responsibility of the receiver to parse this data to recover the IV.
long CIPHER_EncryptHex | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szInputHex, | ||
const char * | szKeyHex, | ||
const char * | szIvHex, | ||
const char * | szAlgModePad, | ||
long | nOptions | ||
) |
Encrypt data using the specified block cipher algorithm, mode and padding.
The input data, key and initialization vector are all represented as hexadecimal strings.
[out] | szOutput | string buffer of sufficient length to receive the output. |
[in] | nOutChars | maximum number of characters to be received. |
[in] | szInputHex | the input data in hex format. |
[in] | szKeyHex | the key in hex format. |
[in] | szIvHex | the initialization vector (IV) in hex format, ignored for ECB mode (use "" ). |
[in] | szAlgModePad | string specifying the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions). |
[in] | nOptions | option flags: Zero (0) for default options. Optionally add: PKI_IV_PREFIX to prepend the IV before the ciphertext in the output (ignored for ECB mode). |
This is the equivalent of CIPHER_EncryptBytes
with all parameters passed as hex-encoded strings instead of byte arrays. It is similar to the CIPHER_Hex
function except this accepts variable-length input and adds padding if required, as well as the option to prepend the IV to the ciphertext.
Padding is added as specified to the input before encryption. The output will always be at least as long as the input, or longer if padding or a prefixed IV is to be added.
The algorithm/mode/padding must be specified using either the szAlgModePad string or nOptions parameter, but not both (see Specifying the algorithm, mode and padding for generic block cipher functions).
It is an error (BAD_PARAM_ERROR
) to pass the empty string ""
as input in szInputHex. The output buffer strOutput should not be the same as the input strInputHex.
Use the PKI_IV_PREFIX
option to prepend the IV before the ciphertext in the output. This will add the IV before the ciphertext in the form IV||CT
. This is the scheme used with block ciphers in XML encryption (see section 5.2 of [XMLENC]) where they use the phrase "The resulting cipher text is prefixed by the IV."
long CIPHER_File | ( | long | fEncrypt, |
const char * | szFileOut, | ||
const char * | szFileIn, | ||
const unsigned char * | lpKey, | ||
const unsigned char * | lpIV, | ||
const char * | szAlgAndMode, | ||
long | nOptions | ||
) |
Encrypt or decrypt data in a file using the specified block cipher algorithm and mode.
[in] | fEncrypt | direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt. |
[in] | szFileOut | with the full path name of the output file to be created. |
[in] | szFileIn | with the full path name of the input file to be processed. |
[in] | lpKey | array containing the key. |
[in] | lpIV | containing the initialization vector (IV), or zero (0) for ECB mode. |
[in] | szAlgAndMode | containing the block cipher algorithm and mode (see Specifying the algorithm and mode for generic block cipher functions). |
[in] | nOptions | option flags. |
The length of key lpKey must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.
The output file szFileOut will be overwritten without warning. If there is an error, the output file will not exist. The input and output files must not be the same.
In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] section 10.3 and [PKCS5] section 6.1.1 and [RFC1423] para 1.1.
long CIPHER_FileDecrypt | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const unsigned char * | lpKey, | ||
long | nKeyLen, | ||
const unsigned char * | lpIV, | ||
long | nIvLen, | ||
const char * | szAlgModePad, | ||
long | nOptions | ||
) |
Decrypt a file using specified block cipher algorithm, mode and padding.
[in] | szFileOut | with the full path name of the output file to be created. |
[in] | szFileIn | with the full path name of the input file to be processed. |
[in] | lpKey | array containing the key. |
[in] | nKeyLen | specifying the length of the key in bytes. |
[in] | lpIV | containing the initialization vector (IV), if required. |
[in] | nIvLen | specifying the length of the IV in bytes. |
[in] | szAlgModePad | containing the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions). |
[in] | nOptions | option flags: Zero (0) for default options. Optionally add: PKI_IV_PREFIX to expect the IV to be prepended at the start of the file (ignored for ECB mode). |
The length of key must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.
The output file szFileOut will be overwritten without warning. If there is an error, the output file will not exist. The input and output files must not be the same.
Prepended IV: If the ciphertext file was created with the IV prepended at the start of the file, then you must specify the PKI_IV_PREFIX
option. In this case, the lpIV parameter is ignored and should be set to NULL. The input file is expected to be of the form IV||ciphertext
, or IV||ciphertext||tag
for AES-GCM.
Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding
will be used for ECB and CBC mode and nopadding
for all other modes. The default cipher mode is ECB
. Thus "aes128"
is the same as "aes128/ecb/pkcs5padding"
.
Padding: When decrypting you can specify NoPadding
to leave any padding intact in the deciphered file. This is useful if you wish to examine an unknown padding scheme. Otherwise, when decrypting in ECB or CBC mode, you must specify the same padding scheme used when encrypting. It is an error (DECRYPT_ERROR
) if the expected padding string is not found after decrypting. The padding parameter is ignored when decrypting in CTR, OFB or CFB mode.
GCM mode: [New in v20.7] Use aes*-gcm
to decrypt the file using AES-GCM mode. A 16-byte tag (mac) must be appended at the end of the file. Only a 16-byte tag is supported. The IV must be exactly 12 bytes long for AES-GCM mode. Use the PKI_IV_PREFIX
flag to indicate that the IV is at the start of the file.
long CIPHER_FileEncrypt | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const unsigned char * | lpKey, | ||
long | nKeyLen, | ||
const unsigned char * | lpIV, | ||
long | nIvLen, | ||
const char * | szAlgModePad, | ||
long | nOptions | ||
) |
Encrypt a file using specified block cipher algorithm, mode and padding.
The IV may be prepended to the file, if required.
[in] | szFileOut | with the full path name of the output file to be created. |
[in] | szFileIn | with the full path name of the input file to be processed. |
[in] | lpKey | array containing the key. |
[in] | nKeyLen | specifying the length of the key in bytes. |
[in] | lpIV | containing the initialization vector (IV), if required. |
[in] | nIvLen | specifying the length of the IV in bytes. |
[in] | szAlgModePad | containing the block cipher algorithm, mode and padding (see Specifying the algorithm, mode and padding for generic block cipher functions). |
[in] | nOptions | option flags: Zero (0) for default options. Optionally add: PKI_IV_PREFIX to prepend the IV before the ciphertext in the output file (ignored for ECB mode). |
The length of key must be exactly the required key size, and the length of the IV, if required, exactly the block size. See Valid key and block sizes.
The output file szFileOut will be overwritten without warning. If there is an error, the output file will not exist. The input and output files must not be the same.
Prepended IV: If the PKI_IV_PREFIX
option flag is set in nOptions then the IV will be prepended (i.e. added) at the start of the output file. That is, the output file will be of the form IV||ciphertext
. The PKI_IV_PREFIX
flag is ignored in ECB mode where an IV is not needed.
Defaults: If padding is not specified then the default padding method depends on the cipher mode: pkcs5padding
will be used for ECB and CBC mode and nopadding
for all other modes. The default cipher mode is ECB
. Thus "aes128"
is the same as "aes128/ecb/pkcs5padding"
.
Padding: In normal circumstances you should leave the padding unspecified and use the default padding when encrypting. The only time it should be required is if you want to use an exotic padding like OneAndZeroesPadding
instead of pkcs5padding
with EBC or CBC mode. Note that, unlike the behaviour with CIPHER_EncryptBytes
, it is an error (BAD_PARAM_ERROR
) to specify NoPadding
when encrypting a file with ECB or CBC mode under any circumstances. The padding option is ignored for CTR, OFB and CFB modes; that is, the default nopadding
is always used for these modes regardless of what is specified (so just use the default, e.g. "aes128/ctr"
).
GCM mode: [New in v21.0] Use aes128-gcm
, aes192-gcm
or aes256-gcm
to encrypt the file using AES-GCM mode. A 16-byte tag (mac) is always appended to the file. The IV must be exactly 12 bytes long for AES-GCM mode. Add the PKI_IV_PREFIX
flag to prepend the IV at the start of the output file (this is in accordance with section 5.2.4 of [XMLENC]).
long CIPHER_Hex | ( | long | fEncrypt, |
char * | szOutput, | ||
long | nOutChars, | ||
const char * | szData, | ||
const char * | szKey, | ||
const char * | szIV, | ||
const char * | szAlgAndMode, | ||
long | nOptions | ||
) |
Encrypt or decrypt data represented as a hexadecimal string.
The key and initialization vector are represented as a hexadecimal string.
[in] | fEncrypt | direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt. |
[out] | szOutput | of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szData | containing the input data in hex format. |
[in] | szKey | containing the key in hex format. |
[in] | szIV | containing the initialization vector (IV) in hex format, or the empty string "" for ECB mode. |
[in] | szAlgAndMode | containing the block cipher algorithm and mode (see Specifying the algorithm and mode for generic block cipher functions). |
[in] | nOptions | option flags. |
Important: The output string szOutput must be dimensioned with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different.
For ECB and CBC modes, the length of the input string szInput must be an exact multiple of the block size encoded in hex characters otherwise a BAD_LENGTH_ERROR
error will occur. It is the responsibility of the user to provide suitable padding before encrypting in those modes and to remove any padding after decrypting.
[New in v20.0] Consider using the newer functions CIPHER_EncryptHex and CIPHER_DecryptHex. These functions take a variable length input and add (or remove) the required padding, and provide the option to prepend the IV to the ciphertext.
long CIPHER_KeyUnwrap | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpData, | ||
long | nDataLen, | ||
const unsigned char * | lpKek, | ||
long | nKekLen, | ||
long | nOptions | ||
) |
Unwrap (decrypt) a content-encryption key with a key-encryption key.
[out] | lpOutput | array of sufficient length to receive the output. |
[in] | nOutBytes | specifying the maximum length of the output array. |
[in] | lpData | array containing the input data (wrapped key). |
[in] | nDataLen | specifying the length of the input data in bytes. |
[in] | lpKek | array containing the key encryption key. |
[in] | nKekLen | specifying the length of the key encryption key. |
[in] | nOptions | option flags: Select the key wrap algorithm from one of the following: PKI_KWRAP_AES128 (or PKI_BC_AES128 ) to use AES128-Wrap PKI_KWRAP_AES192 (or PKI_BC_AES192 ) to use AES128-Wrap PKI_KWRAP_AES256 (or PKI_BC_AES256 ) to use AES128-Wrap PKI_KWRAP_3DES (or PKI_BC_3DES ) to use cms3DESWrap |
long CIPHER_KeyWrap | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpData, | ||
long | nDataLen, | ||
const unsigned char * | lpKek, | ||
long | nKekLen, | ||
long | nOptions | ||
) |
Wrap a content-encryption key with a key-encryption key.
[out] | lpOutput | array of sufficient length to receive the output. |
[in] | nOutBytes | specifying the maximum length of the output array. |
[in] | lpData | array containing the input data (key material). |
[in] | nDataLen | specifying the length of the input data in bytes. |
[in] | lpKek | array containing the key encryption key. |
[in] | nKekLen | specifying the length of the key encryption key. |
[in] | nOptions | option flags: Select the key wrap algorithm from one of the following: PKI_KWRAP_AES128 (or PKI_BC_AES128 ) to use AES128-Wrap PKI_KWRAP_AES192 (or PKI_BC_AES192 ) to use AES128-Wrap PKI_KWRAP_AES256 (or PKI_BC_AES256 ) to use AES128-Wrap PKI_KWRAP_3DES (or PKI_BC_3DES ) to use cms3DESWrap |
Changed in [v20.5]: Added the explicit key wrap options PKI_KWRAP_*
which are different from the old PKI_BC_*
options. The old PKI_BC_*
options are still accepted for backwards compatibility.
long CMS_GetSigDataDigest | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileIn, | ||
const char * | szCertFile, | ||
long | nOptions | ||
) |
Extracts the message digest from a signed-data CMS object file and verifies the signature.
[out] | szOutput | to receive the message digest output. |
[in] | nOutChars | specifying the length of the output string. |
[in] | szFileIn | with name of signed-data CMS object file or the data as a base64 or PEM string. |
[in] | szCertFile | specifying an (optional) X.509 certificate file to be used to identify the signer. |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default options |
messageDigest
attribute for RSA and DSA signature algorithms. If signed attributes are not present, the message digest is extracted directly from the signature value, but only for RSASSA-PKCS1-v1_5 signatures, as the message digest cannot be directly extracted from a DSA or RSA-PSS signature. If given, the function will use the public key from the specified X.509 certificate to validate the signature; otherwise it will use the first valid SignerInfo and certificate pair it finds in the SignedData.The message digest, if found, is copied into szHexDigest. The maximum expected length of szHexDigest is PKI_MAX_HASH_CHARS
characters. ANSI C users must add one to this value when allocating memory. The message digest is encoded in hexadecimal format using lower-case letters [a-f].
The message digest algorithm is indicated by the return code:
Code | Algorithm |
---|---|
PKI_HASH_SHA1 | SHA-1 |
PKI_HASH_MD5 (1) | MD5 |
PKI_HASH_MD2 (2) | MD2 |
PKI_HASH_SHA256 (3) | SHA-256 |
PKI_HASH_SHA384 (4) | SHA-384 |
PKI_HASH_SHA512 (5) | SHA-512 |
PKI_HASH_SHA224 (6) | SHA-224 |
CAUTION: unlike other hash-related functions, this function does not return the length of the digest string; it returns the code for the digest algorithm.
Note that this does not verify that the message digest is that of the content. It does, however, verify that the message digest was indeed signed by the purported signer, but it does not check the content itself. To verify that the SignedData object is validly signed, the user must extract the content separately and verify that its message digest matches the digest extracted by this function. To do this, use the functions CMS_ReadSigDataToString()
and HASH_HexFromBytes()
. See the examples below.
Alternatively, use the CMS_VerifySigData()
to verify the signature and message digest directly and use CMS_QuerySigData()
to extract the messageDigest attribute, if present, without validation.
long CMS_MakeComprData | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
long | nOptions | ||
) |
Creates a new CMS compressed-data file (.p7z) from an existing input file.
[in] | szFileOut | name of output file to be created. |
[in] | szFileIn | name of file containing input data. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
zlibCompress
algorithm. It only works in file-to-file mode. Any existing file with the same name as the parameter szFileOut will be overwritten without warning. Note that it may not produce an exact identical output to that of another program on the same input due to differences in ZLIB buffers and window sizes. long CMS_MakeDetachedSig | ( | const char * | szFileOut, |
const char * | szHexDigest, | ||
const char * | szCertList, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Creates a "detached signature" CMS signed-data object from a message digest of the content.
[in] | szFileOut | with name of output file to be created. |
[in] | szHexDigest | containing the digest of the content in hexadecimal format. |
[in] | szCertList | containing the filename of the signer's certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (; ) |
[in] | szPrivateKey | containing the private key data for the signer. |
[in] | nOptions | option flags: Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmand optionally add PKI_CMS_EXCLUDE_CERTS to exclude signer's certificatePKI_CMS_INCLUDE_ATTRS to add signed attributes (default = no signed attributes) including content-type and message-digest plus any more added below.PKI_CMS_ADD_SIGNTIME to add SigningTime to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SMIMECAP to add sMIMECapabilities to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SIGNINGCERT to add ESS Signing Certificate attribute to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_FORMAT_BASE64 to format the output with base64 encoding (default output is binary) |
CMS_MakeSigData()
for more details. The PKI_CMS_EXCLUDE_DATA
option is obviously ignored. long CMS_MakeEnvData | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const char * | szCertList, | ||
const char * | szKeyString, | ||
long | nCount, | ||
long | nOptions | ||
) |
Create a CMS enveloped-data object for one or more recipients.
[in] | szFileOut | name of output file to be created. |
[in] | szFileIn | name of file containing input data. |
[in] | szCertList | list of one or more recipient X.509 certificate filenames, separated by semicolons (;). A certificate's representation in base64 or as a PEM string may be used instead of a filename. Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b). |
Special cases: Set as "type=@pwri"
to create a single recipientInfo of the PasswordRecipientInfo
(pwri) type; or set as "type=@kekri,keyid=<string>"
to create a single recipientInfo of the KEKRecipientInfo
(kekri) type. See Remarks.
[in] | szKeyString | (formerly szSeed) Use to pass optional additional user key material (ukm) for KDF where KeyAgreement (kari) type or RSA-KEM is used. Or use to pass the password for a pwri type or the key encryption key (KEK) for a kekri type. Either pass a plain ASCII string or use the format "#x<hex-digits>" to pass a string of arbitrary octet values. Required for pwri and kekri types. |
Examples: "abc"
will pass the 3 bytes (0x61, 0x62, 0x63); "#xdeadbeef01"
will pass the 5 bytes (0xde, 0xad, 0xbe, 0xef, 0x01).
[in] | nCount | (formerly nSeedLen) Optional iteration count for KDF in pwri type (default=4096) or tag length for AuthEnvelopedData (in range 12-16, default=16). Otherwise ignored. |
[in] | nOptions | option flags: Set as zero (0) to use the defaults rsaEncryption for key transport or ECDH with ANSI-X9.63-KDF using SHA-1 with cms3DESwrap for key agreement; and aes128-CBC for content encryption, and output in binary format. NOTE: some default algorithms [changed in v23.0] |
To set the content encryption algorithm (default is aes128-CBC
), add one of the following:
PKI_BC_AES128
to use aes128-CBC
for content encryption (default as of [v23.0])
PKI_BC_AES192
to use aes192-CBC
for content encryption
PKI_BC_AES256
to use aes256-CBC
for content encryption
PKI_BC_3DES
to use Triple-DES des-EDE3-CBC
for content encryption [legacy]
PKI_AEAD_AES_128_GCM
to use aes128-GCM
for content encryption and authentication
PKI_AEAD_AES_192_GCM
to use aes192-GCM
for content encryption and authentication
PKI_AEAD_AES_256_GCM
to use aes256-GCM
for content encryption and authentication
PKI_AEAD_CHACHA20_POLY1305
to use AEAD_CHACHA20_POLY1305
for content encryption and authentication
To set the key transport scheme or key encapsulation mechanism (KEM) for RSA, use one of
PKI_KT_RSAES_PKCS
(0) to encrypt the key using the RSAES-PKCS1-v1_5 encryption scheme rsaEncryption
(default)
PKI_KT_RSAES_OAEP
to encrypt the key using the RSAES-OAEP encryption scheme (see RSA signature and encryption schemes).
PKI_KEM_RSA
[New in v23.0] to encrypt the key using the RSA Key Encapsulation Mechanism (RSA-KEM) algorithm (see RSA-KEM).
To select a hash function where applicable, add one of:
PKI_HASH_SHA1
to use SHA-1 (default - CAUTION)
PKI_HASH_SHA224
to use SHA-224
PKI_HASH_SHA256
to use SHA-256 [minimum recommended]
PKI_HASH_SHA384
to use SHA-384
PKI_HASH_SHA512
to use SHA-512
If you have selected PKI_KT_RSAES_OAEP
then, optionally, add
PKI_MGF_MGF1SHA1
to force the MGF hash function to be SHA-1 (default = same as encoding hash function set above)
To set the key derivation function (KDF) (where applicable), add one of:
PKI_KDF_X963
to use the ANSI-X9.63-KDF key derivation function (default for ECDH).
PKI_KDF_HKDF
to use the HMAC-based Key Derivation Function (HKDF) from [RFC5869]
PKI_KDF_KDF2
to use KDF2 from ANSI-X9.44 [X9-44]
PKI_KDF_KDF3
to use KDF3 from ANSI-X9.44 (default for RSA-KEM)
and add the key wrap algorithm for the ECDH key agreement scheme or the kekri key encryption algorithm or RSA-KEM. Default (0) is to match the key agreement algorithm to the content encryption algorithm:
PKI_KWRAP_3DES
to use cms3DESwrap
[legacy - only valid if Triple DES used for the content encryption algorithm].
PKI_KWRAP_AES128
to use aes128-wrap
PKI_KWRAP_AES192
to use aes192-wrap
PKI_KWRAP_AES256
to use aes256-wrap
Optionally, add any of the bitflags:
PKI_CMS_FORMAT_BASE64
to encode the output with base64 encoding (default output is binary)
PKI_CMS_ALT_ALGID
to use specialist alternative encryption algorithm identifier (see Remarks)
PKI_CMS_BIGFILE
to speed up the processing of large files (binary file to binary file only)
PKI_CMS_USE_SKI
to use subjectKeyIdentifier (SKI) instead of issuerAndSerialNumber for RecipientInfo [New in v23.0].
EnvelopedData
or AuthEnvelopedData
object which can be sent as part of an S/MIME message or used directly as a binary .p7m file. The supported objects are those described in CMS Content Types. RecipientInfo types can be KeyTransRecipientInfo
(ktri), KeyAgreeRecipientInfo
(kari), KEKRecipientInfo
(kekri) and PasswordRecipientinfo
(pwri). If the content encryption algorithm is an authenticated encryption algorithm (AES*-GCM
), then the output will be an Authenticated-Enveloped-Data object (AuthEnvelopedData
) as specified in [RFC5083] and [RFC5084].TL;DR. The RecipientInfo type will be set according to the type of public key in the X.509 certificates. If the certificate has an RSA key, then a key-transport RecipientInfo (ktri) will be created (default PKCS#1v1.5 or RSA-OAEP if flag set). If the certificate contains a supported ECC public key, then a key-agreement type (kari) will be used (default ANSI-X9.63-KDF and keywrap to match the content encryption algorithm, HKDF if flag set). You can pass a list of mixed certificates and the appropriate RecipientInfo type will be chosen for each. There are special cases for KEK and password recipientInfo types - see below.
By default, the RecipientInfo
type is set automatically depending on the public key found in each certificate in szCertList, one for each certificate. If the public key is RSA (rsaEncryption) then the key transport technique (ktri) will be used to create that particular recipientInfo
. If the public key is a supported ECC key, then the standard ECDH ephemeral-static key agreement technique (kari) will be used as per [RFC5753] and [RFC8418].
No checks are made on the validity period of the recipients' X.509 certificates or their key usage attributes. A PKCS#7 certificate chain file may be specified as an argument for szCertList. In which case, all certificates in the chain file will be used as recipients.
It is an error if any specified certificate file in szCertList is missing or corrupted. Call PKI_LastError() to find more details of the errors that occurred.
[New in v20.6] RecipientInfo types KEKRecipientInfo
(kekri) and PasswordRecipientinfo
(pwri) are supported for a single recipient only. For these types no certificates are required and the szCertList argument must include "type=@kekri"
or "type=@pwri"
, respectively, all characters lower case. In addition, for a kekri type, this argument should be of the form "type=@kekri,keyid=<string>"
(Note separated by a comma ',') where the value for the keyid attribute is used to set the keyIdentifier
field in the KEKIdentifier
. This can be a simple ASCII string or can use the format "#x<hex-digits>"
to pass a string of arbitrary octet values. If omitted, the default keyIdentifier
is "keyid". Optionally add a date
field in the KEKIdentifier
by adding a date=<iso-date-string>
, e.g. "type=@kekri,keyid=ourkeyid,date=2022-07-31T12:01"
.
The szKeyString argument must include either the key encryption key (KEK) for kekri or the password for pwri. This parameter is expected to be an ASCII string. A binary KEK may be passed by using the format "#x<hex-digits>"
to pass a string of arbitrary octet values.
Examples
nRet = CMS_MakeEnvData("xscipher_kekri.p7m", "plain.txt", "type=@kekri,keyid=oursharedkey", "#x0123456789ABCDEFF0E1D2C3B4A59687", 0, PKI_BC_AES192 Or PKI_KWRAP_AES128);
Creates an EnvelopedData file with a single recipientInfo of type KEKRecipientInfo
(kekri) with a keyid of "oursharedkey" using the 128-bit KEK (0x)0123456789ABCDEFF0E1D2C3B4A59687
wrapped with aes128-wrap
. The content is encrypted with AES-192 using a random content encryption key.
nRet = CMS_MakeEnvData("xscipher_pwri.p7m", "plain.txt", "type=@pwri", "This is my password", 6666, PKI_BC_AES256);
Creates an EnvelopedData file with a single recipientInfo of type PasswordRecipientinfo
(pwri) using the password "This is my password". The iteration count for the KDF is 6666 (default=4096). The content is encrypted with AES-256 using a random content encryption key.
Use the PKI_CMS_BIGFILE
option flag to handle large files more efficiently. This results in improvements of speed typically of 30% and enables, in theory, unlimited sizes of enveloped files (subject, of course, to your level of boredom in waiting for the output). Binary output only. Not available for authenticated encryption or kekri or pwri recipientInfo types.
Specialist Option: If the PKI_CMS_ALT_ALGID
option flag is present, an alternative Content Encryption Algorithm Identifier will be used as follows:
Default Content Encryption Algorithm Identifier | with PKI_CMS_ALT_ALGID |
---|---|
des-ede3-cbc (1.2.840.113549.3.7) | des_3CBC_pad (1.3.36.3.1.3.2.1) |
This alternative TeleTrusT algorithm identifier was added for compatibility with certain (superseded?) German Health profiles.
long CMS_MakeEnvDataFromBytes | ( | const char * | szFileOut, |
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const char * | szCertList, | ||
const char * | szKeyString, | ||
long | nCount, | ||
long | nOptions | ||
) |
Create a CMS enveloped-data object from data in a byte array.
[in] | szFileOut | name of output file to be created. |
[in] | lpInput | byte array containing the input data. |
[in] | nInputLen | length in bytes of input data. |
[in] | szCertList | list of one or more recipient X.509 certificate filenames, separated by semicolons (;). A certificate's representation in base64 or as a PEM string may be used instead of a filename. Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b). |
Special cases: Set as "type=@pwri"
to create a single recipientInfo of the PasswordRecipientInfo
(pwri) type; or set as "type=@kekri,keyid=<string>"
to create a single recipientInfo of the KEKRecipientInfo
(kekri) type. See Remarks.
[in] | szKeyString | (formerly szSeed) Use to pass optional additional user key material (ukm) for KDF where KeyAgreement (kari) type is used. Or use to pass the password for a pwri type or the key encryption key (KEK) for a kekri type. Either pass a plain ASCII string or use the format "#x<hex-digits>" to pass a string of arbitrary octet values. Required for pwri and kekri types. |
Examples: "abc"
will pass the 3 bytes (0x61, 0x62, 0x63); "#xdeadbeef01"
will pass the 5 bytes (0xde, 0xad, 0xbe, 0xef, 0x01).
[in] | nCount | (formerly nSeedLen) Optional iteration count for KDF in pwri type (default=4096) or tag length for AuthEnvelopedData (in range 12-16, default=16). Otherwise ignored. |
[in] | nSeedLen | formerly used for length of the seed string. No longer used. [IGNORED!] |
[in] | nOptions | option flags: see the options in CMS_MakeEnvData. |
CMS_MakeEnvData
except the input data is in a byte array instead of a file.See the remarks for CMS_MakeEnvData()
above.
Use this function if the plaintext contains non-ASCII characters such as UTF-8 encoded.
long CMS_MakeEnvDataFromString | ( | const char * | szFileOut, |
const char * | szDataIn, | ||
const char * | szCertList, | ||
const char * | szKeyString, | ||
long | nCount, | ||
long | nOptions | ||
) |
Create a CMS enveloped-data object from an ASCII string.
[in] | szFileOut | name of output file to be created. |
[in] | szDataIn | string containing input data. |
[in] | szCertList | list of one or more recipient X.509 certificate filenames, separated by semicolons (;). A certificate's representation in base64 or as a PEM string may be used instead of a filename. Alternatively, specify a single PKCS#7 certificate chain file (.p7c/.p7b). |
Special cases: Set as "type=@pwri"
to create a single recipientInfo of the PasswordRecipientInfo
(pwri) type; or set as "type=@kekri,keyid=<string>"
to create a single recipientInfo of the KEKRecipientInfo
(kekri) type. See Remarks.
[in] | szKeyString | (formerly szSeed) Use to pass optional additional user key material (ukm) for KDF where KeyAgreement (kari) type is used. Or use to pass the password for a pwri type or the key encryption key (KEK) for a kekri type. Either pass a plain ASCII string or use the format "#x<hex-digits>" to pass a string of arbitrary octet values. Required for pwri and kekri types. |
Examples: "abc"
will pass the 3 bytes (0x61, 0x62, 0x63); "#xdeadbeef01"
will pass the 5 bytes (0xde, 0xad, 0xbe, 0xef, 0x01).
[in] | nCount | (formerly nSeedLen) Optional iteration count for KDF in pwri type (default=4096) or tag length for AuthEnvelopedData (in range 12-16, default=16). Otherwise ignored. |
[in] | nOptions | option flags: see the options in CMS_MakeEnvData. |
CMS_MakeEnvData
except the input data is in an ASCII string instead of a file.See the remarks for CMS_MakeEnvData()
above. Use this function only when the plaintext is only plain ASCII text, otherwise use CMS_MakeEnvDataFromBytes.
long CMS_MakeSigData | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const char * | szCertList, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Creates a CMS object of type SignedData from an input data file.
[in] | szFileOut | name of output file to be created. |
[in] | szFileIn | name of file containing message data to be signed. |
[in] | szCertList | filename of the signer's certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;). Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer's certificate. |
[in] | szPrivateKey | private key data for the sender in "internal" string format. |
[in] | nOptions | Option flags. Select one of:PKI_SIG_RSA_SHA1 (0) to use RSASSA-PKCS-v1_5 with SHA-1 (sha1WithRSAEncryption ) (default - CAUTION)PKI_SIG_RSA_SHA224 to use RSASSA-PKCS-v1_5 with SHA-224 (sha224WithRSAEncryption )PKI_SIG_RSA_SHA256 to use RSASSA-PKCS-v1_5 with SHA-256 (sha256WithRSAEncryption ) [minimum recommended]PKI_SIG_RSA_SHA384 to use RSASSA-PKCS-v1_5 with SHA-384 (sha384WithRSAEncryption )PKI_SIG_RSA_SHA512 to use RSASSA-PKCS-v1_5 with SHA-512 (sha512WithRSAEncryption )PKI_SIG_RSA_MD5 to use RSASSA-PKCS-v1_5 with MD5 (md5WithRSAEncryption ) [legacy, not recommended for new implementations]PKI_SIG_RSA_PSS_SHA1 to use RSASSA-PSS with SHA-1PKI_SIG_RSA_PSS_SHA224 to use RSASSA-PSS with SHA-224PKI_SIG_RSA_PSS_SHA256 to use RSASSA-PSS with SHA-256PKI_SIG_RSA_PSS_SHA384 to use RSASSA-PSS with SHA-384PKI_SIG_RSA_PSS_SHA512 to use RSASSA-PSS with SHA-512PKI_SIG_ECDSA_SHA1 to use ecdsaWithSHA1 PKI_SIG_ECDSA_SHA224 to use ecdsaWithSHA224 PKI_SIG_ECDSA_SHA256 to use ecdsaWithSHA256 PKI_SIG_ECDSA_SHA384 to use ecdsaWithSHA384 PKI_SIG_ECDSA_SHA512 to use ecdsaWithSHA512 PKI_SIG_ED25519 to use Ed25519 [New in v20.0]PKI_SIG_ED448 to use Ed448 [New in v22.0]And optionally add any combination of the following flags: PKI_CMS_EXCLUDE_CERTS to exclude signer's certificatePKI_CMS_EXCLUDE_DATA to exclude the eContent dataPKI_CMS_CERTS_ONLY to create a "certs-only" PKCS#7 certficate chainPKI_CMS_USE_SKI to use subjectKeyIdentifier (SKI) instead of issuerAndSerialNumber for SignerIdentifier [New in v23.0].PKI_CMS_INCLUDE_ATTRS to add signed attributes (default = no signed attributes) including content-type and message-digest plus any more added below.PKI_CMS_FORMAT_BASE64 to format the output with base64 encoding (default output is binary)PKI_CMS_NO_OUTER to create a "naked" SignedData object with no outerContentInfo as permitted by PKCS#7 v1.6 (specialist option)PKI_CMS_ALT_ALGID to use an alternative signature algorithm identifier (see Remarks)PKI_CMS_BIGFILE to speed up the processing of large files (see Remarks)PKI_PSS_SALTLEN_ZERO to set the salt length to be zero (RSASSA-PSS only, default = same length as the output of the hash function)PKI_MGF_MGF1SHA1 to force the MGF hash function to be SHA-1 (RSASSA-PSS only, default = same as signature hash function)PKI_CMS_PSEUDOSIG to create a create a "pseudo" SignedData object with a dummy placeholder signature (see Remarks)PKI_CMS_ADD_SIGNER to add a new signer to an existing SignedData object [New in v23.0] (see Remarks)If the PKI_CMS_INCLUDE_ATTRS option flag is included, optionally add any of the following:PKI_CMS_ADD_SIGNTIME to add SigningTime to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SMIMECAP to add sMIMECapabilities to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SIGNINGCERT to add an ESS Signing Certificate Attribute to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS ) [New in v12.4]PKI_CMS_ADD_ALGPROTECT to add an Algorithm Identifier Protection Attribute to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS ) [New in v12.4] |
The signer's certificate must be included in the certificate list. All certificates in the list will be included in the output by default. Signed attributes are not included by default but can be added by using the PKI_CMS_INCLUDE_ATTRS
option flag (see below). Unsigned attributes and attribute certificates are not supported. The default signature algorithm is RSASSA-PKCS-v1_5 with SHA-1 (SHA-1 caution!). The message digest algorithm always matches the digest algorithm used in the signature.
The encapContentInfo eContentType is always id-data
: other eContentTypes are not possible. Only one SignerInfo can be included at one time, but [New in v23.0] additional SignerInfos can be added by calling this function second time passing an existing SignedData object as input and setting the PKI_CMS_ADD_SIGNER
(see below). [New in v23.0] The signer's public key can be referenced using either issuerAndSerialNumber
(default) or subjectKeyIdentifier
(use the PKI_CMS_USE_SKI
option). If subjectKeyIdentifier
is used then the CMSversion will be 3 and the relevant SignerInfo version will also be 3. Otherwise the CMSVersion will be 1 and the SignerInfo structure also version 1.
It is an error (NO_MATCH_ERROR
) if the private key does not match any certificate in the certificate list.
[New in v12.2] A PKCS#7 certificate chain file (.p7c/.p7b) may be specified as an argument for szCertList. The signer's certificate can now exist anywhere in the certificate list (previously it had to be the first).
PKI_CMS_CERTS_ONLY: To create a PKCS#7 certificate chain (a degenerate "certs-only" signed data object), include the option flag PKI_CMS_CERTS_ONLY
. The szCertList can contain references to any existing certificate files in any order, separated by semi-colons. The szFileIn and szPrivateKey parameters are ignored and can be left empty. See the second example below.
PKI_CMS_INCLUDE_ATTRS: Signed attributes are not included by default. To add signed attributes use the PKI_CMS_INCLUDE_ATTRS
option flag. This will add the content-type and message-digest attributes plus any other attributes specified using a PKI_CMS_ADD_*
option.
PKI_CMS_ADD_SIGNINGCERT: [New in v12.4] Include the PKI_CMS_ADD_SIGNINGCERT
option to add an ESS Signing Certificate Attribute to the signed attributes. This is required for B-level compliance with CAdES-BES [CADES] and with ESS [RFC2634] and [RFC5035].
PKI_CMS_ADD_ALGPROTECT: [New in v12.4] Include the PKI_CMS_ADD_ALGPROTECT
option to add an Algorithm Protection Attribute to the signed attributes. This is in accordance with [RFC6211]. If a CMS validator supports this attribute, then additional checks can be made against algorithm substitution attacks.
PKI_CMS_BIGFILE: Include the PKI_CMS_BIGFILE
option to cope more efficiently with large files. This only works in binary-file-to-binary-file mode, and only for RSA signatures, but makes a significant difference in processing times. The option flags PKI_CMS_EXCLUDE_DATA
, PKI_CMS_CERTS_ONLY
, PKI_CMS_FORMAT_BASE64
, and PKI_CMS_NO_OUTER
are not permitted with this option.
PKI_CMS_ADD_SIGNER: [New in v23.0] To sign an existing SignedData object with another signature, use the PKI_CMS_ADD_SIGNER
option and pass the existing SignedData object as the input data file. Pass the signer's certificate in szCertList (plus any additional certificates if required) and the signer's private key string in szPrivateKey.
PKI_PSS_SALTLEN_ZERO: [New in v12.0] Include the PKI_PSS_SALTLEN_ZERO
with an RSA-PSS scheme to set the salt length parameter to be zero. This results in a deterministic signature value. The default salt length is otherwise always hLen
, the length of the output of the hash function. There are no other salt length options available for this function. See RSA signature and encryption schemes.
PKI_CMS_ALT_ALGID: If the PKI_CMS_ALT_ALGID
option flag is present, an alternative Signature Algorithm Identifier will be used as follows (RSAES-PKCS-v1_5 only):
Message Digest Algorithm | Default Signature Algorithm Identifier | Alternative ID with PKI_CMS_ALT_ALGID |
---|---|---|
SHA-1 (default, PKI_SIG_RSA_SHA1 ) | rsaEncryption (1.2.840.113549.1.1) | sha1withRSAEncryption (1.2.840.113549.1.1.5) |
MD5 (with PKI_SIG_RSA_MD5 ) | rsaEncryption (1.2.840.113549.1.1) | md5withRSAEncryption (1.2.840.113549.1.1.4) |
SHA-224 (with PKI_SIG_RSA_SHA224 ) | rsaEncryption (1.2.840.113549.1.1) | sha224withRSAEncryption (1.2.840.113549.1.1.14) |
SHA-256 (with PKI_SIG_RSA_SHA256 ) | rsaEncryption (1.2.840.113549.1.1) | sha256withRSAEncryption (1.2.840.113549.1.1.11) |
SHA-384 (with PKI_SIG_RSA_SHA384 ) | rsaEncryption (1.2.840.113549.1.1) | sha384withRSAEncryption (1.2.840.113549.1.1.12) |
SHA-512 (with PKI_SIG_RSA_SHA512 ) | rsaEncryption (1.2.840.113549.1.1) | sha512withRSAEncryption (1.2.840.113549.1.1.13) |
The default is to use the rsaEncryption
identifier specified in Section 3.2 of [CMSALG].
PKI_CMS_PSEUDOSIG: [New in v20.2] Include the PKI_CMS_PSEUDOSIG
option to create a create a "pseudo" SignedData object. The idea here is that we create an intermediate file which has the same structure as a CMS SignedData object except the signature is a dummy placeholder. We use the term "pseudo" file here to describe this intermediate file.
This pseudo file has the same digest value as the final signed object (as the digest is not calculated over the final signature). We send this digest value to a signing authority (say, Aruba), they sign it, and send back the actual signature value. This can be substituted in the intermediate pseudo file to produce the final SignedData object (.p7m file) using CMS_MakeSigDataFromSigValue with the PKI_CMS_PSEUDOSIG
option. RSASSA-PKCS1V1_5 only.
Specialist Option: If the PKI_CMS_NO_OUTER
option flag is present, the output will be a "naked" SignedData object without an outerContentInfo
. This is not permitted by the CMS standard [CMS] but is allowed by PKCS#7 version 1.6 [PKCS7-EXT]. Some profiles (e.g. Royal Thai Customs) require this.
long CMS_MakeSigDataFromBytes | ( | const char * | szFileOut, |
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const char * | szCertList, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Create a CMS object of type SignedData from an array of bytes.
[in] | szFileOut | name of output file to be created. |
[in] | lpInput | byte array containing input data to be signed. |
[in] | nInputLen | length in bytes of input data. |
[in] | szCertList | filename of the signer's certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;). Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer's certificate. |
[in] | szPrivateKey | private key data for the sender in "internal" string format. |
[in] | nOptions | Option flags. Select one of:PKI_SIG_RSA_SHA1 (0) to use RSASSA-PKCS-v1_5 with SHA-1 (sha1WithRSAEncryption ) (default - CAUTION)PKI_SIG_RSA_SHA224 to use RSASSA-PKCS-v1_5 with SHA-224 (sha224WithRSAEncryption )PKI_SIG_RSA_SHA256 to use RSASSA-PKCS-v1_5 with SHA-256 (sha256WithRSAEncryption ) [minimum recommended]PKI_SIG_RSA_SHA384 to use RSASSA-PKCS-v1_5 with SHA-384 (sha384WithRSAEncryption )PKI_SIG_RSA_SHA512 to use RSASSA-PKCS-v1_5 with SHA-512 (sha512WithRSAEncryption )PKI_SIG_RSA_MD5 to use RSASSA-PKCS-v1_5 with MD5 (md5WithRSAEncryption ) [legacy, not recommended for new implementations]PKI_SIG_RSA_PSS_SHA1 to use RSASSA-PSS with SHA-1PKI_SIG_RSA_PSS_SHA224 to use RSASSA-PSS with SHA-224PKI_SIG_RSA_PSS_SHA256 to use RSASSA-PSS with SHA-256PKI_SIG_RSA_PSS_SHA384 to use RSASSA-PSS with SHA-384PKI_SIG_RSA_PSS_SHA512 to use RSASSA-PSS with SHA-512PKI_SIG_ECDSA_SHA1 to use ecdsaWithSHA1 PKI_SIG_ECDSA_SHA224 to use ecdsaWithSHA224 PKI_SIG_ECDSA_SHA256 to use ecdsaWithSHA256 PKI_SIG_ECDSA_SHA384 to use ecdsaWithSHA384 PKI_SIG_ECDSA_SHA512 to use ecdsaWithSHA512 PKI_SIG_ED25519 to use Ed25519 [New in v20.0]PKI_SIG_ED2448 to use Ed448 [New in v22.0]and optionally add any of the following flags: PKI_CMS_EXCLUDE_CERTS to exclude signer's certificatePKI_CMS_EXCLUDE_DATA to exclude the eContent dataPKI_CMS_CERTS_ONLY to create a "certs-only" PKCS#7 certficate chainPKI_CMS_INCLUDE_ATTRS to add signed attributes (default = no signed attributes) including content-type and message-digest plus any more added below.PKI_CMS_FORMAT_BASE64 to format the output with base64 encoding (default output is binary)PKI_CMS_NO_OUTER to create a "naked" SignedData object with no outerContentInfo as permitted by PKCS#7 v1.6 (specialist option)PKI_CMS_ALT_ALGID to use an alternative signature algorithm identifier (see Remarks)PKI_CMS_BIGFILE to speed up the processing of large files (see Remarks)PKI_PSS_SALTLEN_ZERO to set the salt length to be zero (RSASSA-PSS only, default = same length as the output of the hash function)PKI_MGF_MGF1SHA1 to force the MGF hash function to be SHA-1 (RSASSA-PSS only, default = same as signature hash function)If the PKI_CMS_INCLUDE_ATTRS option flag is included, optionally add any of the following:PKI_CMS_ADD_SIGNTIME to add SigningTime to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SMIMECAP to add sMIMECapabilities to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SIGNINGCERT to add an ESS Signing Certificate Attribute to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS ) [New in v12.4]PKI_CMS_ADD_ALGPROTECT to add an Algorithm Identifier Protection Attribute to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS ) [New in v12.4] |
CMS_MakeSigData()
except the input is passed as a byte array instead of in a file.See the remarks for CMS_MakeSigData
above.
Use this function if the content contains non-ASCII characters such as UTF-8 encoded.
long CMS_MakeSigDataFromSigValue | ( | const char * | szFileOut, |
const unsigned char * | lpSigValue, | ||
long | nSigLen, | ||
const unsigned char * | lpData, | ||
long | nDataLen, | ||
const char * | szCertList, | ||
long | nOptions | ||
) |
Creates a CMS object of type SignedData using a pre-computed signature value.
[in] | szFileOut | name of output file to be created. |
[in] | lpSigValue | byte array containing the pre-computed signature. |
[in] | nSigLen | length of the signature value in bytes. |
[in] | lpData | byte array containing the data that has been signed (required). |
[in] | nDataLen | length of the data in bytes. |
[in] | szCertList | filename of the signer's certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;). Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer's certificate. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_MD5 to use the MD5 algorithmand optionally add PKI_CMS_EXCLUDE_CERTS to exclude signer's certificatePKI_CMS_FORMAT_BASE64 to format the output with base64 encoding (default output is binary)PKI_CMS_NO_OUTER to create a "naked" SignedData object with no outerContentInfo as permitted by PKCS#7 v1.6PKI_CMS_ALT_ALGID to use alternative signature algorithm identifiers (see Remarks for CMS_MakeSigData() )PKI_CMS_PSEUDOSIG to create a SignedData object from a "pseudo" object (see Remarks). |
A SignedData CMS object with a single SignerInfo is created with the message data included in the eContent. Signed attributes cannot be added. Unsigned attributes and attribute certificates are not supported. The content must be included in the input using the lpData and nDataLen parameters. Only RSASSA-PKCS-v1_5 signature schemes are supported by this function. Only one message digest algorithm is used in each object. SHA-1 is used by default. Alternative hash algorithms can be used instead by adding the appropriate PKI_HASH_
option flag (this must match the digest algorithm used to compute the signature). The content and the signature are checked before the output file is created. If the signature data is not valid, or the data is not the data signed, or the certificate specified is not that of the signer, then it will return SIGNATURE_ERROR (-22).
[New in v12.2] A PKCS#7 certificate chain file (.p7c/.p7b) may be specified as an argument for szCertList. The signer's certificate can now exist anywhere in the certificate list (previously it had to be the first).
[New in v20.2] Use the PKI_CMS_PSEUDOSIG
option to create a SignedData object from a "pseudo" object, created using CMS_MakeSigData with the PKI_CMS_PSEUDOSIG
option.
long CMS_MakeSigDataFromString | ( | const char * | szFileOut, |
const char * | szDataIn, | ||
const char * | szCertList, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Create a CMS object of type SignedData from an input string.
[in] | szFileOut | name of output file to be created. |
[in] | szDataIn | string containing message data to be signed. |
[in] | szCertList | filename of the signer's certificate and (optionally) a list of other certificates to be included in the output, separated by semi-colons (;). Alternatively specify a single PKCS#7 certificate chain file (.p7c/.p7b) containing the signer's certificate. |
[in] | szPrivateKey | private key data for the sender in "internal" string format. |
[in] | nOptions | Option flags. Select one of:PKI_SIG_RSA_SHA1 (0) to use RSASSA-PKCS-v1_5 with SHA-1 (sha1WithRSAEncryption ) (default - CAUTION)PKI_SIG_RSA_SHA224 to use RSASSA-PKCS-v1_5 with SHA-224 (sha224WithRSAEncryption )PKI_SIG_RSA_SHA256 to use RSASSA-PKCS-v1_5 with SHA-256 (sha256WithRSAEncryption ) [minimum recommended]PKI_SIG_RSA_SHA384 to use RSASSA-PKCS-v1_5 with SHA-384 (sha384WithRSAEncryption )PKI_SIG_RSA_SHA512 to use RSASSA-PKCS-v1_5 with SHA-512 (sha512WithRSAEncryption )PKI_SIG_RSA_MD5 to use RSASSA-PKCS-v1_5 with MD5 (md5WithRSAEncryption ) [legacy, not recommended for new implementations]PKI_SIG_RSA_PSS_SHA1 to use RSASSA-PSS with SHA-1PKI_SIG_RSA_PSS_SHA224 to use RSASSA-PSS with SHA-224PKI_SIG_RSA_PSS_SHA256 to use RSASSA-PSS with SHA-256PKI_SIG_RSA_PSS_SHA384 to use RSASSA-PSS with SHA-384PKI_SIG_RSA_PSS_SHA512 to use RSASSA-PSS with SHA-512PKI_SIG_ECDSA_SHA1 to use ecdsaWithSHA1 PKI_SIG_ECDSA_SHA224 to use ecdsaWithSHA224 PKI_SIG_ECDSA_SHA256 to use ecdsaWithSHA256 PKI_SIG_ECDSA_SHA384 to use ecdsaWithSHA384 PKI_SIG_ECDSA_SHA512 to use ecdsaWithSHA512 PKI_SIG_ED25519 to use Ed25519 [New in v20.0]PKI_SIG_ED448 to use Ed448 [New in v22.0]and optionally add any of the following flags: PKI_CMS_EXCLUDE_CERTS to exclude signer's certificatePKI_CMS_EXCLUDE_DATA to exclude the eContent dataPKI_CMS_CERTS_ONLY to create a "certs-only" PKCS#7 certficate chainPKI_CMS_INCLUDE_ATTRS to add signed attributes (default = no signed attributes) including content-type and message-digest plus any more added below.PKI_CMS_FORMAT_BASE64 to format the output with base64 encoding (default output is binary)PKI_CMS_NO_OUTER to create a "naked" SignedData object with no outerContentInfo as permitted by PKCS#7 v1.6 (specialist option)PKI_CMS_ALT_ALGID to use an alternative signature algorithm identifier (see Remarks)PKI_PSS_SALTLEN_ZERO to set the salt length to be zero (RSASSA-PSS only, default = same length as the output of the hash function)PKI_MGF_MGF1SHA1 to force the MGF hash function to be SHA-1 (RSASSA-PSS only, default = same as signature hash function)If the PKI_CMS_INCLUDE_ATTRS option flag is included, optionally add any of the following:PKI_CMS_ADD_SIGNTIME to add SigningTime to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SMIMECAP to add sMIMECapabilities to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS )PKI_CMS_ADD_SIGNINGCERT to add an ESS Signing Certificate Attribute to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS ) [New in v12.4]PKI_CMS_ADD_ALGPROTECT to add an Algorithm Identifier Protection Attribute to the signed attributes (requires PKI_CMS_INCLUDE_ATTRS ) [New in v12.4] |
CMS_MakeSigData()
except the input is passed as a string instead of in a file.Zero-terminated ANSI data is expected in szDataIn.
To sign a messsage that contains binary or Unicode UTF-8 or UTF-16 data, use CMS_MakeSigDataFromBytes
.
long CMS_QueryEnvData | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileIn, | ||
const char * | szQuery, | ||
long | nOptions | ||
) |
Queries a CMS enveloped-data object file for selected information.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the length of the output string. |
[in] | szFileIn | with name of signed-data CMS object file or the data as a base64 or PEM string. |
[in] | szQuery | specifying the query (see Remarks below). |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default optionsPKI_QUERY_GETTYPE to return the type of data returned for a given query. |
"version"
, "VERSION"
and "VeRsIoN"
are all valid.Valid queries are (case-insensitive):
Query String | Returns | Data Type |
---|---|---|
version | envelopedData CMSVersion (edVer ) value | Number |
recipientInfoVersion | recipientInfo version (riVer ) value | Number |
recipientInfoType | Type of recipientInfo: ktri , kari , kekri , pwri , ori | String |
CountOfRecipientInfos | Number of RecipientInfos included in the data | Number |
recipientIssuerName | Distinguished Name of recipient's certificate issuer | String |
recipientSerialNumber | serialNumber of recipient's certificate in hex format | String |
keyEncryptionAlgorithm | keyEncryptionAlgorithm, e.g. "rsaEncryption" | String |
keyEncryptionFlags | Bit flags used for the key encryption algorithm (ktri only) | Number |
SizeOfEncryptedKey | Size (in bytes) of the EncryptedKey | Number |
encryptedKey | EncryptedKey value encoded in hex | String |
oaepParams | Parameters used for RSA-OAEP (if applicable). | String |
kemParams | Parameters used for RSA-KEM (if applicable) [New in v23.0] | String |
keyWrapAlgorithm | Key wrap algorithm, e.g. "aes128-wrap" (kari and kekri only) | String |
originatorKeyAlgorithm | OriginatorPublicKey algorithm, e.g. "ecPublicKey" (kari only) | String |
originatorPublicKey | OriginatorPublicKey publicKey value encoded in hex (kari only) | String |
keyid | keyIdentifier for KEKRecipientInfo (kekri) type | String |
ukm | User Keying Material (if applicable) [New in v23.0] | String |
contentEncryptionAlgorithm | contentEncryptionAlgorithm, e.g. "des-EDE3-CBC" | String |
SizeOfEncryptedContent | Size (in bytes) of the EncryptedContent | Number |
encryptedContent | EncryptedContent encoded in hex | String |
iv | Initialization vector for encrypted content encoded in hex | String |
HASsubjectKeyIdentifier | 1 if recipientIdentifier is the CHOICE subjectKeyIdentifier; 0 if issuerAndSerialNumber [New in v23.0] | Number |
recipientIdentifier | recipientIdentifier value encoded in hex [New in v23.0] | String |
By default, the function queries the first recipientInfo in the file. To query the Nth recipientInfo append "/N" to the query string, e.g. "recipientInfoVersion/2"
to find the version number of the second recipientInfo in the file. The query encryptedContent
may be slow to respond if the file is large.
The "raw" VBA/C function behaves differently depending on whether the output is a string or a number. If the result data type is a number then it returns the value directly. If the result is a string, then it sets szOutput and returns the number of characters in the string. The required number of characters can be found by passing zero for nOutChars or a null string for szOutput. ANSI C users must add one to this value when allocating memory.
Note that the VBA wrapper function and the C#/VB.NET and C++ (STL) methods always return a string, which is different from the behaviour of the raw VB6/C function.
To find out the type of data returned for a given query, use the PKI_QUERY_GETTYPE
option. The function will return either PKI_QUERY_NUMBER
(1) or PKI_QUERY_STRING
(2), or a negative "invalid query" error. For example
nRet = CMS_QueryEnvData("", 0, "", "version", PKI_QUERY_GETTYPE);
will return PKI_QUERY_NUMBER
.
long CMS_QuerySigData | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileIn, | ||
const char * | szQuery, | ||
long | nOptions | ||
) |
Queries a CMS signed-data object file for selected information.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the length of the output string. |
[in] | szFileIn | with name of signed-data CMS object file or the data as a base64 or PEM string. |
[in] | szQuery | specifying the query (see Remarks below). |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default optionsPKI_QUERY_GETTYPE to return the type of data returned for a given query. |
"version"
, "Version"
and "VeRsIoN"
are all valid.Valid queries are (case-insensitive):
Query String | Returns | Data Type |
---|---|---|
version | signedData version (sdVer ) value | Number |
eContentType | ContentType of the EncapsulatedContentInfo, e.g. "data" | String |
HASeContent | 1 if eContent is present; 0 if not | Number |
CountOfCertificates | Number of certificates in the SignedData | Number |
CountOfSignerInfos | Number of SignerInfos in the SignedData | Number |
CountOfDigestAlgs | Number of DigestAlgorithmIdentifiers in the SignedData [New in v23.0] | Number |
certificate/N | Nth certificate encoded in base64 [New in v23.0] | String |
signerInfoVersion | signerInfo version (siVer ) value | Number |
digestAlgorithm | digestAlgorithm, e.g. "sha1" | String |
signatureAlgorithm | signatureAlgorithm, e.g. "rsaEncryption" | String |
signatureValue | Signature value encoded in hex | String |
HASsignedAttributes | 1 if signedAttributes (authenticatedAttributes) are present; 0 if not | Number |
DigestOfSignedAttrs | Computed digest over signed attributes, if present, using digestAlgorithm | String |
DigestOfeContent | Computed digest over eContent, if present, using digestAlgorithm | String |
signingTime | signingTime attribute in format "2005-12-31 23:30:59" | String |
messageDigest | messageDigest attribute in hexadecimal format, if present | String |
pssParams | Parameters used for RSA-PSS (if applicable). | String |
HASsigningCertificate | 1 if an ESS signingCertificate is present; 0 if not. | Number |
signingCertHash | certHash value of ESS signing certificate, if present, encoded in hex | String |
HASalgorithmProtection | 1 if a cmsAlgorithmProtection attribute is present; 0 if not. | Number |
HASsubjectKeyIdentifier | 1 if signerIdentifier is the CHOICE subjectKeyIdentifier; 0 if issuerAndSerialNumber [New in v23.0] | Number |
signerIdentifier | signerIdentifier value encoded in hex [New in v23.0] | String |
By default, the function queries the first signerInfo in the file. To query the Nth signerInfo append "/N" to the query string, e.g. "signerInfoVersion/2"
to find the version number of the second signerInfo in the file.
[New in v23.0] The query "certificate/N"
will output the Nth certificate in the CertificateSet (default N = 1) encoded in base64. Note that the length of an X.509 certificate is typically several hundred bytes.
The "raw" VBA/C function behaves differently depending on whether the output is a string or a number. If the result data type is a number then it returns the value directly. If the result is a string, then it sets szOutput and returns the number of characters in the string. The required number of characters can be found by passing zero for nOutChars or a null string for szOutput. ANSI C users must add one to this value when allocating memory.
Note that the VBA wrapper function and the C#/VB.NET methods always return a string, which is different from the behaviour of the raw VB6/C function.
To find out the type of data returned for a given query, use the PKI_QUERY_GETTYPE
option. The function will return either PKI_QUERY_NUMBER
(1) or PKI_QUERY_STRING
(2), or a negative "invalid query" error. For example
nRet = CMS_QuerySigData("", 0, "", "version", PKI_QUERY_GETTYPE);
will return PKI_QUERY_NUMBER
.
long CMS_ReadComprData | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
long | nOptions | ||
) |
Read and extract the decompressed contents of a CMS compressed-data file.
[in] | szFileOut | name of output file to be created. |
[in] | szFileIn | name of file containing input data. |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default optionsPKI_CMS_NO_INFLATE to extract the compressed data as is without inflation |
zlibCompress
algorithm. It only works in file-to-file mode. Any existing file with the same name as the parameter szFileOut will be overwritten without warning. Use the PKI_CMS_NO_INFLATE
option to extract the compressed data as is without inflation. long CMS_ReadEnvData | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const char * | szCertFile, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Read and decrypt a CMS enveloped-data object to a file.
[in] | szFileOut | with name of output file to be created. |
[in] | szFileIn | with name of file containing input data (binary or base64-encoded) or the data as a base64 or PEM string. |
[in] | szCertFile | (optional) specifies the filename of the recipient's X.509 certificate. |
[in] | szPrivateKey | recipient's private key in internal string format. |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default options.PKI_CMS_BIGFILE to speed up the processing of large files (binary only). |
The optional certificate szCertFile is used to identify the intended recipient in a message addressed to multiple recipients. If the intended recipient's certificate is not provided, the first valid message that can be decrypted using the given private key, if any, will be extracted.
The supported EnvelopedData
and AuthEnvelopedData
objects are those described in CMS Content Types.
Use the PKI_CMS_BIGFILE
option to process large files more efficiently. See the example in CMS_MakeEnvData()
.
[Changes in v12.1] To avoid certain attacks that rely on timing differences, the encrypted content will always be decrypted. If all else is good but no valid content encryption key (CEK) can be found in the recipient data, then a random key will be used. The end result in this latter case will always be a negative DECRYPT_ERROR
with no further information as to the cause. If there is something obviously wrong with the input, such as a badly-formed input file (INVALID_DATA_ERROR
), or the given certificate does not have a match with any recipient (NO_MATCH_ERROR
), then an appropriate error code will be returned.
long CMS_ReadEnvDataToBytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szFileIn, | ||
const char * | szCertFile, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Reads and decrypts CMS enveloped-data object using the recipient's private key writing the plaintext data directly into a byte array.
[out] | lpOutput | buffer to receive output plaintext. |
[in] | nOutBytes | length in bytes of the output buffer. |
[in] | szFileIn | name of file containing input data (binary or base64-encoded) or the data as a base64 or PEM string. |
[in] | szCertFile | (optional) filename of the recipient's X.509 certificate. |
[in] | szPrivateKey | recipient's private key in internal string format. |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default options |
CMS_ReadEnvData()
above. Call the function with a NULL lpOutput or zero nOutBytes parameter to find out the required length of the output buffer. Alternatively, use the CMS_QueryEnvData()
function with the query "sizeofEncryptedContent"
. This will return an upper bound on the length of the decrypted plaintext, at most 16 bytes too long. Calling CMS_ReadEnvDataToString()
with a properly-sized output buffer will return the exact size of the recovered plaintext. The buffer must be large enough to receive the entire output or a SHORT_BUF_ERROR
error will result.Use this function if the output plaintext is known to contain non-ASCII characters such as UTF-8 encoded.
long CMS_ReadEnvDataToString | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileIn, | ||
const char * | szCertFile, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Reads and decrypts CMS enveloped-data object using the recipient's private key writing the plaintext data directly into a string.
[out] | szOutput | buffer to receive output plaintext. |
[in] | nOutChars | length in bytes of the output buffer. |
[in] | szFileIn | name of file containing input data (binary or base64-encoded) or the data as a base64 or PEM string. |
[in] | szCertFile | (optional) filename of the recipient's X.509 certificate. |
[in] | szPrivateKey | recipient's private key in internal string format. |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default options |
See the remarks for CMS_ReadEnvData()
above.
Alternatively, use the CMS_QueryEnvData()
function with the query "sizeofEncryptedContent"
. This will return an upper bound on the length of the decrypted plaintext, at most 16 bytes too long. Calling CMS_ReadEnvDataToString()
with a properly-sized output buffer will return the exact size of the recovered plaintext. The buffer must be large enough to receive the entire output or a SHORT_BUF_ERROR
error will result.
Use this function only if the output plaintext is known to be plain ASCII text with no embedded NUL (zero) characters, otherwise use CMS_ReadEnvDataToBytes.
long CMS_ReadSigData | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
long | nOptions | ||
) |
Reads the content from a CMS signed-data object file.
[in] | szFileOut | with name of output file to be created. |
[in] | szFileIn | with name of signed-data CMS object file (binary or base64-encoded) or the data as a base64 or PEM string. |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default optionsPKI_CMS_BIGFILE to speed up the processing of large files (binary input only). |
This function automatically checks for and reads "naked" SignedData files as per PKCS#7 version 1.6 [PKCS7-EXT] as well as the default SignedData objects properly encapsulated in an outerContentInfo as per the S/MIME standard.
long CMS_ReadSigDataToBytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szFileIn, | ||
long | nOptions | ||
) |
Reads the content from a CMS signed-data object file directly into a byte array.
[out] | lpOutput | buffer to receive the output. |
[in] | nOutBytes | length of the output buffer. |
[in] | szFileIn | with name of signed-data CMS object file (binary or base64-encoded) or the data as a base64 or PEM string. |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default options |
SHORT_BUF_ERROR
error will result.Use this function if the content contains non-ASCII characters such as UTF-8 encoded.
long CMS_ReadSigDataToString | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileIn, | ||
long | nOptions | ||
) |
Reads the content from a CMS signed-data object file directly into a string.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the length of the output string. |
[in] | szFileIn | with name of signed-data CMS object file (binary or base64-encoded) or the data as a base64 or PEM string. |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default options |
This function extracts the signed data from the signed-data CMS object without making any attempt to verify it.
The buffer must be large enough to receive the entire output or a SHORT_BUF_ERROR
error will result.
Use this only when the signed content is known to be plain ASCII text, otherwise use CMS_ReadSigDataToBytes.
long CMS_VerifySigData | ( | const char * | szFileIn, |
const char * | szCertFile, | ||
const char * | szHexDigest, | ||
long | nOptions | ||
) |
Verifies the signature and content of a signed-data CMS object file.
[in] | szFileIn | specifying the name of the signed-data CMS object file (binary or base64-encoded) or the data as a base64 or PEM string. |
[in] | szCertFile | (optional) specifying an X.509 certificate file to be used to identify the signer. Specify an empty string "" to use the certificate(s) in the input file. |
[in] | szHexDigest | (optional) specifying a message digest encoded in hexadecimal format. Use this to verify a "detached-signature" input file. Specify an empty string "" to verify the eContent data in the SignedData file. |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default options.PKI_CMS_BIGFILE to speed up the processing of large files (binary input only). |
If the signed content (eContent) is included in the SignedData object (this is the usual case), then specify an empty string (""
) for szHexDigest. For a "detached-signature" file where the signed content has been passed to the user by other means, compute a separate message digest of the data and pass it to the function in the szHexDigest parameter.
This function handles SignedData objects both with and without signedAttributes.
[New in v12.4] If an ESS Signing Certificate attribute is found, then the purported signing certificate will be checked against the value of this attribute as per ESS [RFC5035] and CAdES [CADES]. It is a SIGNATURE_ERROR
(22) if these do not match.
[New in v12.4] If an Algorithm Protection Attribute is found, then further verification checks will be made to prevent algorithm substitution attacks as per [RFC6211]. It is a SIGNATURE_ERROR
(22) if these checks fail.
long CNV_B64Filter | ( | char * | szOutput, |
const char * | szInput, | ||
long | nStrLen | ||
) |
Removes non-base64 characters from a string.
[out] | szOutput | to receive filtered characters. |
[in] | szInput | to be filtered. |
[in] | nStrLen | specifying the length of the input string. |
Assumes that the output string is at least as long as the input string.
long CNV_B64StrFromBytes | ( | char * | szOutput, |
long | nOutChars, | ||
const unsigned char * | lpInput, | ||
long | nInputLen | ||
) |
Encodes an array of bytes into a base64-encoded string.
[out] | szOutput | to receive encoded data. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | lpInput | array of binary data to be encoded. |
[in] | nInputLen | number of bytes to be encoded. |
This uses the base64 encoding scheme from [RFC4648]. Pass a zero value of nOutChars to find the required maximum possible number of characters in the output string. The final result may be smaller. C/C++ programmers should add one to the returned length value when allocating memory for szOutput.
long CNV_Base58FromBytes | ( | char * | szOutput, |
long | nOutChars, | ||
const unsigned char * | lpInput, | ||
long | nInputLen | ||
) |
Encodes an array of bytes into a base58-encoded string.
[out] | szOutput | to receive encoded data. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | lpInput | array of binary data to be encoded. |
[in] | nInputLen | number of bytes to be encoded. |
This uses the "Bitcoin" scheme of base58 encoding where the leading character '1' is reserved for representing an entire leading zero byte [BTC-B58].
long CNV_Base58ToBytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szInput | ||
) |
Decodes a base58-encoded string into an array of bytes.
[out] | lpOutput | array suitably dimensioned to receive decoded output. |
[in] | nOutBytes | specifying the maximum number of bytes to be received. |
[in] | szInput | base58 data to be decoded. |
long CNV_ByteEncoding | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nBytes, | ||
long | nOptions | ||
) |
Converts encoding of byte array between UTF-8 and Latin-1.
[out] | lpOutput | array suitably dimensioned to receive output.. |
[in] | nOutBytes | specifying the maximum number of bytes to be received. |
[in] | lpInput | array containing input data. |
[in] | nBytes | number of bytes in input array. |
[in] | nOptions | Option flags. Select one of:PKI_CNV_UTF8_FROM_LATIN1 (1) to convert from UTF-8 encoding to Latin-1PKI_CNV_LATIN1_FROM_UTF8 (2) to convert from Latin-1 encoding to UTF-8 |
long CNV_BytesFromB64Str | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szInput | ||
) |
Decodes a base64-encoded string into an array of Bytes.
[out] | lpOutput | array suitably dimensioned to receive output. |
[in] | nOutBytes | specifying the maximum number of bytes to be received. |
[in] | szInput | base64 data to be decoded. |
long CNV_BytesFromHexStr | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szInput | ||
) |
Decodes a hexadecimal-encoded string into an array of Bytes.
[out] | lpOutput | array suitably dimensioned to receive output. |
[in] | nOutBytes | specifying the length of the byte array. |
[in] | szInput | of hexadecimal data to be decoded. |
"DE:AD:BE:EF"
is OK) but characters like those in the range [G-Zg-z]
that are obviously non-hex will cause an error. long CNV_CheckUTF8 | ( | const char * | szInput | ) |
Checks if a string only contains valid UTF-8 characters.
[in] | szInput | to be checked. |
long CNV_CheckUTF8Bytes | ( | const unsigned char * | lpInput, |
long | nBytes | ||
) |
Checks if a byte array contains valid UTF-8 characters.
[in] | lpInput | array to be checked. |
[in] | nBytes | number of bytes in input array. |
Returns | Value | Result |
---|---|---|
PKI_CHRS_NOT_UTF8 | 0 | Not valid UTF-8 |
PKI_CHRS_ALL_ASCII | 1 | Valid UTF-8, all chars are 7-bit ASCII |
PKI_CHRS_ANSI8 | 2 | Valid UTF-8, contains at least one multi-byte character equivalent to 8-bit ANSI |
PKI_CHRS_MULTIBYTE | 3 | Valid UTF-8, contains at least one multi-byte character that cannot be represented in a single-byte character set. |
Overlong UTF-8 sequences and illegal surrogates are rejected as invalid. Strings that return PKI_CHRS_ANSI8
(2) can be converted to Latin-1 format using the CNV_Latin1FromUTF8Bytes()
function. Strings that return PKI_CHRS_MULTIBYTE
(3) cannot be converted to Latin-1, and strings that return PKI_CHRS_ALL_ASCII
(1) are already OK because they only consist of 7-bit ASCII characters.
long CNV_CheckUTF8File | ( | const char * | szFileName | ) |
Checks if a file contains valid UTF-8 characters.
[in] | szFileName | containing the name of the file. |
CNV_CheckUTF8Bytes()
but for a file instead of a byte array. For more details, see CNV_CheckUTF8Bytes()
. long CNV_HexFilter | ( | char * | szOutput, |
const char * | szInput, | ||
long | nStrLen | ||
) |
Removes non-hexadecimal characters from a string.
[out] | szOutput | to receive filtered characters. |
[in] | szInput | to be filtered. |
[in] | nStrLen | specifying the length of the input string. |
Assumes that the output string is at least as long as the input string.
long CNV_HexStrFromBytes | ( | char * | szOutput, |
long | nOutChars, | ||
const unsigned char * | lpInput, | ||
long | nInputLen | ||
) |
Encodes an array of bytes into a hexadecimal-encoded string.
[out] | szOutput | to receive encoded data. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | lpInput | array of binary data to be encoded. |
[in] | nInputLen | number of bytes to be encoded. |
The input array may contain bytes of any value. If vbNullString
or an empty string (""
) is specified for szHex or zero for nHexStrLen, the function will return the maximum possible size of the encoded string. The final result may be smaller. C/C++ programmers should add one to the returned length value when allocating memory.
long CNV_Latin1FromUTF8 | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szInput | ||
) |
Converts a UTF-8 string into a Latin-1 string, if possible.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szInput | of UTF-8 characters to be converted. |
long CNV_Latin1FromUTF8Bytes | ( | char * | szOutput, |
long | nOutChars, | ||
const unsigned char * | lpInput, | ||
long | nBytes | ||
) |
Converts UTF-8 encoded array of bytes into a Latin-1 string, if possible.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | lpInput | array containing UTF-8 encoded data. |
[in] | nBytes | number of bytes in input array. |
The input must be valid UTF-8 data. Possible errors are INVALID_DATA_ERROR indicating invalid UTF-8 input and OUT_OF_RANGE_ERROR which indicates that the output would contain a character greater than 8 bits in size.
long CNV_NumFromBytes | ( | const unsigned char * | lpInput, |
long | nBytes, | ||
long | nOptions | ||
) |
Converts the leftmost four bytes of an array to a 32-bit integer.
[in] | lpInput | Byte array to be converted. |
[in] | nBytes | number of bytes. |
[in] | nOptions | Option flags. Select one of:PKI_CNV_BIG_ENDIAN (0) for big-endian order (default)PKI_CNV_LITTLE_ENDIAN for little-endian order |
long CNV_NumToBytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
long | nNumber, | ||
long | nOptions | ||
) |
Converts a 32-bit integer to an array of 4 bytes.
[out] | lpOutput | byte array to receive output. |
[in] | nOutBytes | size of output array in bytes. |
[in] | nNumber | integer to be converted. |
[in] | nOptions | Option flags. Select one of:PKI_CNV_BIG_ENDIAN (0) for big-endian order (default)PKI_CNV_LITTLE_ENDIAN for little-endian order |
long CNV_ReverseBytes | ( | unsigned char * | lpOutput, |
const unsigned char * | lpInput, | ||
long | nBytes | ||
) |
Reverses the order of a byte array.
[out] | lpOutput | byte array to receive output. |
[in] | lpInput | array of bytes to be reversed. |
[in] | nBytes | number of bytes. |
long CNV_ShortPathName | ( | char * | szOut, |
long | nOutChars, | ||
const wchar_t * | szwFilePath | ||
) |
Retrieve the Windows short path form of the specified path.
[out] | szOut | Buffer to receive output. |
[in] | nOutChars | Maximum length of output string in bytes (excluding the terminating null). |
[in] | szwFilePath | Path name in wide characters. |
wchar_t
characters. Then use this ASCII short name as an argument for an input file in any of the functions in this library that require a file name.The file must exist. The output path is guaranteed to be in ASCII characters, and the base name and each folder name will be 8 characters or fewer. It may not give the same value on a different system. Windows only.
For the "raw" function, pass a NULL szOut or zero nOutChars to find the required output length in bytes. ANSI C users must add one to this value when allocating memory.
long CNV_UTF8BytesFromLatin1 | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szInput | ||
) |
Converts a string of 8-bit Latin-1 characters into a UTF-8 encoded array of bytes.
[out] | lpOutput | array suitably dimensioned to receive output. |
[in] | nOutBytes | specifying the maximum number of bytes to be received. |
[in] | szInput | of Latin-1 characters to be converted. |
long CNV_UTF8FromLatin1 | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szInput | ||
) |
Converts a string of 8-bit Latin-1 characters into UTF-8 format.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szInput | of Latin-1 characters to be converted. |
long CNV_Utf8FromWide | ( | char * | szOut, |
long | nOutChars, | ||
const wchar_t * | wstr | ||
) |
Maps a UTF-16 (wide character) string to a UTF-8-encoded string.
[out] | szOut | Buffer to receive null-terminated UTF-8-encoded string. |
[in] | nOutChars | Maximum length of output string in bytes (excluding the terminating null). |
[in] | wstr | String of wide characters to be processed. |
wchar_t
characters to a UTF-8-encoded string of type char
.For the "raw" ANSI function, pass a NULL szOut or zero nOutChars to find the required output length in bytes. Allocate one extra byte for the terminating null.
This function is for C/C++ programmers only. There is no VBA or .NET equivalent.
long COMPR_Compress | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
long | nOptions | ||
) |
Compress data using zlib compression.
[out] | lpOutput | byte buffer to receive output data. |
[in] | nOutBytes | size of the output buffer in bytes. |
[in] | lpInput | input data to be compressed. |
[in] | nInputLen | length of input array in bytes. |
[in] | nOptions | option flags. Not used in this release. Set to zero. |
long COMPR_Uncompress | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
long | nOptions | ||
) |
Uncompress data using zlib compression.
[out] | lpOutput | byte buffer to receive output data. |
[in] | nOutBytes | size of the output buffer in bytes. |
[in] | lpInput | input data to be uncompressed. |
[in] | nInputLen | length of input array in bytes. |
[in] | nOptions | option flags. Not used in this release. Set to zero. |
long ECC_DHSharedSecret | ( | unsigned char * | lpZZ, |
long | nOutBytes, | ||
const char * | szIntPrivateKey, | ||
const char * | szIntPublicKey, | ||
long | nOptions | ||
) |
Compute EC Diffie-Hellman (ECDH) shared secret.
[out] | lpZZ | Buffer to receive shared secret as an array of bytes. |
[in] | nOutBytes | Length of output buffer in bytes. |
[in] | szIntPrivateKey | String containing our own private key in ephemeral "internal" form. |
[in] | szIntPublicKey | String containing other party's public key in "internal" form. |
[in] | nOptions | Not used in this release. Specify zero. |
ECC_ReadPrivateKey
, ECC_ReadPublicKey
or ECC_ReadKeyByCurve
. All supported NIST/SEC curves can be used as well as the safe curve X25519 (but not Ed25519 or Ed448, which are for signatures only). long ECC_KeyHashCode | ( | const char * | szKeyString | ) |
Computes the hash code of an "internal" ECC public or private key string.
[in] | szKeyString | containing the ECC private or public key string in internal format. |
If the key string is invalid, the return value is zero and a nonzero error code will be set (use PKI_ErrorCode
to check). There is a very small chance (one in 4 billion) that a valid key string returns a hash code of zero.
long ECC_MakeKeys | ( | const char * | szPubKeyFile, |
const char * | szPriKeyFile, | ||
const char * | szCurveName, | ||
const char * | szPassword, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Generates an EC public/private key pair and saves as two key files.
[in] | szPubKeyFile | name of public key file to be created. |
[in] | szPriKeyFile | name of encrypted private key file to be created. |
[in] | szCurveName | name of elliptic curve (see remarks). |
[in] | szPassword | the password to be used for the encrypted key file. |
[in] | szParams | (optional) parameters. Set as the empty string "" for defaults. Otherwise include a set of attribute-value pairs separated by a semi-colon ";" to set options from the following
{hmacWithSHA1|hmacWithSHA224|hmacWithSHA256|hmacWithSHA384|hmacWithSHA512} . |
[in] | nOptions | containing a flag to indicate the password-based encryption scheme to be used to encrypt the private key file. Select from:PKI_PBE_SHA_3DES (0) for "pbeWithSHAAnd3-KeyTripleDES-CBC" (default)PKI_PBE_PBKDF2_DESEDE3 for PBKDF2 using des-EDE3-CBC PKI_PBE_PBKDF2_AES128 for PBKDF2 using aes128-CBC PKI_PBE_PBKDF2_AES192 for PBKDF2 using aes192-CBC PKI_PBE_PBKDF2_AES256 for PBKDF2 using aes256-CBC (there are more options - see security options for encrypted private keys) and optionally add PKI_KEY_FORMAT_PEM to save the key files in PEM form (default is binary DER-encoded format). |
SubjectPublicKeyInfo
and EncryptedPrivateKeyInfo
respectively. Any existing files of the same names will be overwritten without warning. The password should be a string of non-zero ASCII characters.The key is stored by default as a pair of DER-encoded binary files. Use the PKI_KEY_FORMAT_PEM
flag to save in PEM-encoded format.
Supported curve names for szCurveName are:
Curve name | Alternative names | Remarks |
---|---|---|
secp192r1 | P-192 , P_192 , prime192v1 | NIST |
secp256r1 | P-256 , P_256 , prime256v1 | NIST |
secp224r1 | P-224 , P_224 | NIST |
secp384r1 | P-384 , P_384 | NIST |
secp521r1 | P-521 , P_521 | NIST |
secp256k1 | Bitcoin/SEC | |
Ed25519 | For EdDSA signatures | |
X25519 | For ECDH key exchange | |
Ed448 | For EdDSA signatures | |
X448 | For ECDH key exchange | |
brainpoolP256r1 | [RFC5639] | |
brainpoolP384r1 | [RFC5639] | |
brainpoolP512r1 | [RFC5639] |
Valid values for the "prf" parameter in szParams are:
hmacWithSHA1
(default) hmacWithSHA224
hmacWithSHA256
hmacWithSHA384
hmacWithSHA512
These are case-insensitive and work only with the PKI_PBE_PBKDF2_
options. This will override any PKI_HMAC_
flag in nOptions
Set szParams as the empty string ""
for defaults.
long ECC_PublicKeyFromPrivate | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szIntKeyString, | ||
long | nOptions | ||
) |
Converts an internal EC private key string into an internal EC public key string.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szIntKeyString | containing the private key as an internal key string. |
[in] | nOptions | not used in this release. Specify zero. |
Use this to derive the public key from the EC private key, where both values are represented as "internal" key strings.
long ECC_QueryKey | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szIntKeyString, | ||
const char * | szQuery, | ||
long | nOptions | ||
) |
Queries an EC key string for selected information.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szIntKeyString | containing the key as an internal key string. |
[in] | szQuery | specifying the query (see Remarks below). |
[in] | nOptions | not used in this release. Specify zero. |
Query String | Returns | Data Type |
---|---|---|
curveName | Name of the curve | String |
keyBits | Number of bits in the key | Number |
isPrivate | 1 if the key is a private key; 0 if not | Number |
isValid | 1 if the key is valid; 0 if not | Number |
privateKey | Value of the private key in hex format | String |
publicKey | Value of the public key in hex format | String |
The "raw" VBA/C function behaves differently depending on whether the output is a string or a number. If the result data type is a number then it returns the value directly. If the result is a string, then it sets szOutput and returns the number of characters in the string. The required number of characters can be found by passing zero for nOutChars or a null string for szOutput. ANSI C users must add one to this value when allocating memory.
Note that the VBA wrapper function and the C#/VB.NET methods always return a string, which is different from the behaviour of the raw VB6/C function.
long ECC_ReadKeyByCurve | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szHexKey, | ||
const char * | szCurveName, | ||
long | nOptions | ||
) |
Reads an EC key from its hexadecimal (base16) representation.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szHexKey | containing a hexadecimal (base16) representation of the key |
[in] | szCurveName | containing the name of the elliptic curve (see remarks) |
[in] | nOptions | For Safe Curves specify PKI_ECC_PRIVATE_KEY or PKI_ECC_PUBLIC_KEY to indicate that the key value represents a private or public key, respectively. Otherwise, nOptions is ignored. |
The output string is an ephemeral internal key string valid only for the current session. This internal key string can be used directly by functions such as ECC_DHSharedSecret or SIG_SignData. You can analyze the key string using ECC_QueryKey or save it in one of the supported key file formats using ECC_SaveKey or ECC_SaveEncKey. The input string is expected to be the hexadecimal (base16) representation of a private or public key.
NIST/SEC/Brainpool curves: A private key is represented by the hexadecimal encoding of its integer value encoded in octets as per section 3 of [RFC5915]. A public key is represented by the hexadecimal encoding of the octet string as defined in section 4.3.6 of [X9-63]; that is, 04||Px||Py
.
Only the uncompressed form of a public key (beginning "04") is supported due to patent issues. It is an error if the key value is out of range or not a valid point on the curve.
Safe curves: Both private and public keys are represented by the hexadecimal encoding of its integer value encoded as a byte array in little-endian form as per [RFC7748] and [RFC8032]. For Ed25519 and X25519, the input string szHexKey is always expected to be a hexadecimal representation of exactly 32 bytes. Set nOptions as PKI_ECC_PRIVATE_KEY
(default 0) or PKI_ECC_PUBLIC_KEY
to indicate whether the key value represents a private or public key, respectively. Any 32-byte key string will be accepted as input and any required bit masking (e.g. for an X25519 private key) will be applied before use.
Supported curve names for szCurveName are:
Curve name | Alternative names | Remarks |
---|---|---|
secp192r1 | P-192 , P_192 , prime192v1 | NIST |
secp224r1 | P-224 , P_224 | NIST |
secp256r1 | P-256 , P_256 , prime256v1 | NIST |
secp384r1 | P-384 , P_384 | NIST |
secp521r1 | P-521 , P_521 | NIST |
secp256k1 | SEC/Bitcoin | |
Ed25519 | Safe EdDSA curve [RFC8032] | |
Ed448 | Safe EdDSA curve [RFC8032] | |
X25519 | Safe ECDH curve [RFC7748] | |
X448 | Safe ECDH curve [RFC7748] | |
brainpoolP256r1 | [RFC5639] | |
brainpoolP384r1 | [RFC5639] | |
brainpoolP512r1 | [RFC5639] |
long ECC_ReadPrivateKey | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyFileOrString, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Reads an EC private key from a file into an internal key string.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyFileOrString | specifying either the name of file containing the key or a string containing the key in PEM format. |
[in] | szPassword | password for the key file, if encrypted; otherwise set as "" . |
[in] | nOptions | not used in this release. Specify zero. |
This reads both encrypted private keys and the unencrypted PKCS#8 PrivateKeyInfo and ECPrivateKey formats. Set szPassword as the empty string ""
if not required.
long ECC_ReadPublicKey | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyFileOrString, | ||
long | nOptions | ||
) |
Reads an EC public key from a file into an internal key string.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyFileOrString | specifying either the name of file containing the key or a string containing the key in PEM format. |
[in] | nOptions | not used in this release. Specify zero. |
[New in v12.0] An EC public key can also be read directly from an X.509 certificate (or its base64 representation).
long ECC_SaveEncKey | ( | const char * | szFileOut, |
const char * | szIntKeyString, | ||
const char * | szPassword, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Saves an internal EC private key string to an encrypted private key file.
[in] | szFileOut | name of key file to be created. |
[in] | szIntKeyString | the private key in an internal key string. |
[in] | szPassword | the password to be used for the encrypted key file |
[in] | szParams | (optional) parameters. Set as the empty string "" for defaults. Otherwise include a set of attribute-value pairs separated by a semi-colon ";" to set options from the following
|
[in] | nOptions | containing a flag to indicate the algorithm to be used to encrypt the private key file. Select from:PKI_PBE_SHA_3DES (0) for "pbeWithSHAAnd3-KeyTripleDES-CBC" (default)PKI_PBE_PBKDF2_DESEDE3 for PBKDF2 using des-EDE3-CBC PKI_PBE_PBKDF2_AES128 for PBKDF2 using aes128-CBC PKI_PBE_PBKDF2_AES192 for PBKDF2 using aes192-CBC PKI_PBE_PBKDF2_AES256 for PBKDF2 using aes256-CBC (there are more options - see security options for encrypted private keys) and optionally add PKI_KEY_FORMAT_PEM to save the key files in PEM form (default is binary DER-encoded format). |
PKI_KEY_FORMAT_PEM
flag to save in PEM-encoded format. You must first read in the old private key file into an "internal" private key string which is only valid for the current session.Valid values for the "prf" parameter in szParams are:
hmacWithSHA1
(default) hmacWithSHA224
hmacWithSHA256
hmacWithSHA384
hmacWithSHA512
These are case-insensitive and work only with the PKI_PBE_PBKDF2_
options. This will override any PKI_HMAC_
flag in nOptions
Set szParams as the empty string ""
for defaults.
long ECC_SaveKey | ( | const char * | szFileOut, |
const char * | szIntKeyString, | ||
long | nOptions | ||
) |
Saves an internal EC key string to an unencrypted key file.
[in] | szFileOut | name of key file to be created. |
[in] | szIntKeyString | the private or public EC key in an internal key string. |
[in] | nOptions | choose one of
PKI_KEY_FORMAT_PEM to save the key file in PEM form (default is binary DER-encoded format). PKI_KEY_LEGACY to save a safe key in "legacy" PKCS#8 v1 format (default is v2 OneAsymmetricKey). |
SubjectPublicKeyInfo
format [RFC5480]. By default, NIST/SEC curve private keys are saved in ECPrivateKey
format [RFC5915]. Use the PKI_KEY_TYPE_PKCS8
option to save in PKCS#8 PrivateKeyInfo
format [RFC5208].[New in v22.0] Safe curve private keys (X25519, Ed25519, X448 and Ed448) are always saved in PKCS#8 v2 OneAsymmetricKey
format including the public key [RFC5958]. Add the option PKI_KEY_LEGACY
to save in older PKCS#8 v1 PrivateKeyInfo
format [RFC5208] excluding the public key.
To save a private key in encrypted form, use ECC_SaveEncKey.
long HASH_Bytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const void * | lpMessage, | ||
long | nMsgLen, | ||
long | nOptions | ||
) |
Creates a message digest hash as a byte array from byte data.
The hash algorithm to use is passed in the options parameter.
[out] | lpOutput | array to receive the hash digest. |
[in] | nOutBytes | specifying the length in bytes of the output array. |
[in] | lpMessage | array containing the message data |
[in] | nMsgLen | specifying length of the message data in bytes. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithmPKI_HASH_MD2 to use the MD2 algorithm (legacy applications)PKI_HASH_RMD160 to use the RIPEMD-160 algorithmPKI_HASH_BTC160 to use the Bitcoin160 algorithm, RIPEMD160(SHA256(m)) and optionally add PKI_HASH_DOUBLE to compute a double hash, HASH(HASH(m)) |
PKI_MAX_HASH_BYTES
. Hint: SHA-1 requires 20 bytes; MD5 and MD2 require 16 bytes; SHA-512 requires 64. The final digest will be truncated to the specified length if less than the expected size. long HASH_File | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szFileName, | ||
long | nOptions | ||
) |
Creates a message digest hash in byte format for a file.
The hash algorithm to use is passed in the options parameter.
[out] | lpOutput | array to receive the hash digest. |
[in] | nOutBytes | specifying the length in bytes of the output array. |
[in] | szFileName | containing the name of the file. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithmPKI_HASH_MD2 to use the MD2 algorithm (legacy applications)PKI_HASH_RMD160 to use the RIPEMD-160 algorithmPKI_HASH_BTC160 to use the Bitcoin160 algorithm, RIPEMD160(SHA256(m)) and optionally add PKI_HASH_DOUBLE to compute a double hash, HASH(HASH(m)) and add PKI_HASH_MODE_TEXT to hash in "text" mode instead of default "binary" mode |
PKI_MAX_HASH_BYTES
. The final digest will be truncated to the specified length if less than the expected size. Add the option PKI_HASH_MODE_TEXT
to work in "text" mode where CR-LF pairs are treated as a single newline (LF) character. (This option is provided if you need to pass hash digests of text files between Windows and Unix systems.) The default mode is "binary" where each byte is treated individually. Only ANSI characters are supported in file names and paths. long HASH_HexFromBytes | ( | char * | szOutput, |
long | nOutChars, | ||
const void * | lpMessage, | ||
long | nMsgLen, | ||
long | nOptions | ||
) |
Creates a message digest hash in hexadecimal format from byte (or string) data.
The hash algorithm to use is passed in the options parameter.
[out] | szOutput | to receive hash digest in hexadecimal format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | lpMessage | array containing the message data; or |
[in] | nMsgLen | specifying length of the message data in bytes. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithmPKI_HASH_MD2 to use the MD2 algorithm (legacy applications)PKI_HASH_RMD160 to use the RIPEMD-160 algorithmPKI_HASH_BTC160 to use the Bitcoin160 algorithm, RIPEMD160(SHA256(m)) and optionally add PKI_HASH_DOUBLE to compute a double hash, HASH(HASH(m)) |
The maximum number of output characters is PKI_MAX_HASH_CHARS
(C/C++ users add one).
The final digest will be truncated to the specified length if less than the expected size.
long HASH_HexFromFile | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileName, | ||
long | nOptions | ||
) |
Creates a message digest hash in hexadecimal format for a file.
The hash algorithm to use is passed in the options parameter.
[out] | szOutput | to receive hash digest in hexadecimal format. |
[in] | nOutChars | specifying the maximum number of characters to be received in characters. |
[in] | szFileName | containing the name of the file. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithmPKI_HASH_MD2 to use the MD2 algorithm (legacy applications)PKI_HASH_RMD160 to use the RIPEMD-160 algorithmPKI_HASH_BTC160 to use the Bitcoin160 algorithm, RIPEMD160(SHA256(m)) and optionally add PKI_HASH_DOUBLE to compute a double hash, HASH(HASH(m)) and add PKI_HASH_MODE_TEXT to hash in "text" mode instead of default "binary" mode |
The maximum number of output characters will be PKI_MAX_HASH_CHARS
(C/C++ users add one). The final digest will be truncated to the specified length if less than the expected size. Add the option PKI_HASH_MODE_TEXT
to work in "text" mode where CR-LF pairs are treated as a single newline (LF) character. (This option is provided if you need to pass hash digests of text files between Windows and Unix systems.) The default mode is "binary" where each byte is treated individually. Only ANSI characters are supported in file names and paths.
long HASH_HexFromHex | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szMsgHex, | ||
long | nOptions | ||
) |
Creates a message digest hash in hexadecimal format from data in a hexadecimal-encoded string.
The hash algorithm to use is passed in the options parameter.
[out] | szOutput | to receive hash digest in hexadecimal format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szMsgHex | containing the message data in hexadecimal-encoded format. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithmPKI_HASH_MD2 to use the MD2 algorithm (legacy applications)PKI_HASH_RMD160 to use the RIPEMD-160 algorithmPKI_HASH_BTC160 to use the Bitcoin160 algorithm, RIPEMD160(SHA256(m)) and optionally add PKI_HASH_DOUBLE to compute a double hash, HASH(HASH(m)) |
The maximum number of output characters is PKI_MAX_HASH_CHARS
(C/C++ users add one). The final digest will be truncated to the specified length if less than the expected size. Valid input hex digits are [0-9A-Fa-f]. The output is always in lower-case letters.
long HASH_Length | ( | long | nAlgId | ) |
Return length of message digest output in bytes.
[in] | nAlgId | Algorithm Id flag. Select one of PKI_HASH_* or PKI_HMAC_* , for example:PKI_HASH_SHA1 SHA-1 algorithmPKI_HASH_SHA224 SHA-224 algorithmPKI_HASH_SHA256 SHA-256 algorithmPKI_HASH_SHA384 SHA-384 algorithmPKI_HASH_SHA512 SHA-512 algorithmPKI_HASH_SHA3_224 SHA-3-224 algorithmPKI_HASH_SHA3_256 SHA-3-256 algorithmPKI_HASH_SHA3_384 SHA-3-384 algorithmPKI_HASH_SHA3_512 SHA-3-512 algorithmPKI_HASH_MD5 MD5 algorithmPKI_HASH_MD2 MD2 algorithmPKI_HASH_RMD160 RIPEMD-160 algorithmPKI_HASH_BTC160 Bitcoin160 algorithm, RIPEMD160(SHA256(m)) |
long HMAC_Bytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const void * | lpMessage, | ||
long | nMsgLen, | ||
const void * | lpKey, | ||
long | nKeyLen, | ||
long | nOptions | ||
) |
Creates a keyed-hash based message authentication code (HMAC) as a byte array from byte data.
The hash algorithm to use is passed in the options parameter.
[out] | lpOutput | array to receive the hash digest. |
[in] | nOutBytes | specifying the length in bytes of the output array. |
[in] | lpMessage | array containing the message data |
[in] | nMsgLen | specifying length of the message data in bytes. |
[in] | lpKey | array containing the key |
[in] | nKeyLen | specifying length of the key in bytes. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
PKI_XXX_BYTES
constant. The maximum possible length is PKI_MAX_HASH_BYTES
. The final digest will be truncated to the specified length if less than the expected size. MD2 is not available with the HMAC functions. long HMAC_HexFromBytes | ( | char * | szOutput, |
long | nOutChars, | ||
const void * | lpMessage, | ||
long | nMsgLen, | ||
const void * | lpKey, | ||
long | nKeyLen, | ||
long | nOptions | ||
) |
Creates a keyed-hash based message authentication code (HMAC) in hexadecimal format from byte data.
The hash algorithm to use is passed in the options parameter.
[out] | szOutput | to receive output in hexadecimal format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | lpMessage | array containing the message data in a byte array |
[in] | nMsgLen | specifying length of the message data in bytes. |
[in] | lpKey | array containing the key in a byte array |
[in] | nKeyLen | specifying length of the key in bytes. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
The maximum number of output characters is PKI_MAX_HASH_CHARS
(C/C++ users add one). C/C++ users should add one to this value when allocating memory. The final digest will be truncated to the specified length if less than the expected size. MD2 is not available with the HMAC functions.
long HMAC_HexFromHex | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szMsgHex, | ||
const char * | szKeyHex, | ||
long | nOptions | ||
) |
Creates a keyed-hash based message authentication code (HMAC) in hexadecimal format from data in hexadecimal-encoded strings.
The hash algorithm to use is passed in the options parameter.
[out] | szOutput | to receive output in hexadecimal format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szMsgHex | containing the message data in hexadecimal-encoded format. |
[in] | szKeyHex | containing the key in hexadecimal-encoded format. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_SHA3_224 to use the SHA-3-224 algorithmPKI_HASH_SHA3_256 to use the SHA-3-256 algorithmPKI_HASH_SHA3_384 to use the SHA-3-384 algorithmPKI_HASH_SHA3_512 to use the SHA-3-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
The maximum number of output characters is PKI_MAX_HASH_CHARS
(C/C++ users add one). C/C++ users should add one to this value when allocating memory. The final digest will be truncated to the specified length if less than the expected size. MD2 is not available with the HMAC functions.
Note the order of parameters here (data, key) is different from the usual order HMAC(key, text).
long HPKE_DerivePrivateKey | ( | char * | szOutput, |
long | nOutChars, | ||
const unsigned char * | lpIkm, | ||
long | nIkmLen, | ||
const char * | szCurveName, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Derive an EC private key in a deterministic manner from input keying material using the DeriveKeyPair algorithm in RFC9180.
[out] | szOutput | string of sufficient length to receive the derived private key. |
[in] | nOutChars | maximum number of characters to be received. |
[in] | lpIkm | byte array containing the input key material (ikm). This must have length in bytes at least as long as the key to be produced. |
[in] | nIkmLen | length of the input key material in bytes. |
[in] | szCurveName | name of ECDH curve: Specify one of:"P-256" | "P-384" | "P-521" | "X25519" | "X448" |
[in] | szParams | (optional) parameters. Not used in this version. Set as the empty string "". |
[in] | nOptions | Option flags. Select one of: Zero (0) to output the private key in ephemeral "internal" key format (default); or PKI_ENCODE_HEX to output the private key in serialized hex form. |
ECC_SaveKey
, ECC_SaveEncKey
, ECC_PublicKeyFromPrivate
, ECC_DHSharedSecret
and ECC_QueryKey
. If nOptions is set to PKI_ENCODE_HEX
then the key is output in serialized hexadecimal form in the same manner as the test vectors in [RFC9180] (without the clamping).For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
This function derives an ECDH private key in the deterministic manner described in [RFC9180] using user-provided input key material (ikm). There is very, very small chance that a valid key cannot be generated from the ikm; in which case the function will return a negative KEYGEN_FAILED_ERROR
error code.
The input key material must have length in bytes at least as long as the key to be produced (Nsk) or a BAD_LENGTH_ERROR
error code will be returned. The values of Nsk (the length in bytes of a Diffie-Hellman private key) for the supported EC curves are as follows:
EC curve group | Nsk |
---|---|
P-256 | 32 |
P-384 | 48 |
P-521 | 66 |
X25519 | 32 |
X448 | 56 |
The KDF to be used is fixed by the EC curve group. See Hybrid Public Key Encryption (HPKE).
long HPKE_LabeledExpand | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpPrk, | ||
long | nPrkLen, | ||
const char * | szLabel, | ||
const unsigned char * | lpInfo, | ||
long | nInfoLen, | ||
const char * | szCurveName, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Compute the output of the LabeledExpand function as defined in RFC9180.
[out] | lpOutput | byte array to be filled with output keying material. |
[in] | nOutputLen | required size of the output key in bytes (L). |
[in] | lpPrk | byte array containing the pseudorandom key (prk). |
[in] | nPrkLen | length of prk in bytes. |
[in] | szLabel | label string. |
[in] | lpInfo | byte array containing optional string info |
[in] | nInfoLen | length of info in bytes (can be zero) |
[in] | szCurveName | name of ECDH curve used in scheme (required): Specify one of:"P-256" | "P-384" | "P-521" | "X25519" | "X448" |
[in] | szParams | (optional) parameters. Not used in this version. Set as the empty string "". |
[in] | nOptions | Option flags. Use to specify the AEAD encryption algorithm used in the scheme (if applicable). Specify either: Zero (0) to indicate that the KDF is being used inside a KEM algorithm or, if used in the remainder of HPKE, one of: PKI_AEAD_AES_128_GCM PKI_AEAD_AES_256_GCM PKI_AEAD_CHACHA20_POLY1305 |
The LabeledExpand
function is defined in section 4 of [RFC9180]. It uses the "expand" stage of the HKDF function [RFC5869].
Because this is a standalone function with no context, the ECDH curve group used in the scheme must be specified. This automatically fixes the KDF and associated HMAC algorithm to be used as per Table 2 of [RFC9180]. In the case where the KDF is being used inside a KEM algorithm, the AEAD algorithm is not used and nOptions must be set to zero . In the other case where the KDF is being used in the remainder of the HPKE scheme, an explicit AEAD algorithm must be specified in nOptions. For more details see Hybrid Public Key Encryption (HPKE).
long HPKE_LabeledExtract | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpSalt, | ||
long | nSaltLen, | ||
const char * | szLabel, | ||
const unsigned char * | lpIkm, | ||
long | nIkmLen, | ||
const char * | szCurveName, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Compute the output of the LabeledExtract function as defined in RFC9180.
[out] | lpOutput | byte array to be filled with a pseudorandom key of fixed length. |
[in] | nOutputLen | length of the output array in bytes. |
[in] | lpSalt | byte array containing the optional salt. |
[in] | nSaltLen | length of salt in bytes (can be zero). |
[in] | szLabel | label string. |
[in] | lpIkm | byte array containing input keying material (ikm). |
[in] | nIkmLen | length of ikm in bytes. |
[in] | szCurveName | name of ECDH curve used in scheme (required): Specify one of:"P-256" | "P-384" | "P-521" | "X25519" | "X448" |
[in] | szParams | (optional) parameters. Not used in this version. Set as the empty string "". |
[in] | nOptions | Option flags. Use to specify the AEAD encryption algorithm used in the scheme (if applicable). Specify either: Zero (0) to indicate that the KDF is being used inside a KEM algorithm or, if used in the remainder of HPKE, one of: PKI_AEAD_AES_128_GCM PKI_AEAD_AES_256_GCM PKI_AEAD_CHACHA20_POLY1305 |
LabeledExtract
function is defined in section 4 of [RFC9180]. It uses the "extract" stage of the HKDF function [RFC5869]. It outputs a fixed value of bytes equal to the length (Nh) of the underlying HMAC function used by the KDF algorithm.Because this is a standalone function with no context, the ECDH curve group used in the scheme must be specified. This automatically fixes the KDF and associated HMAC algorithm to be used as per Table 2 of [RFC9180]. In the case where the KDF is being used inside a KEM algorithm, the AEAD algorithm is not used and nOptions must be set to zero . In the other case where the KDF is being used in the remainder of the HPKE scheme, an explicit AEAD algorithm must be specified in nOptions. For more details see Hybrid Public Key Encryption (HPKE).
long KDF_Bytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const void * | lpIKM, | ||
long | nIkmLen, | ||
const void * | lpInfo, | ||
long | nInfoLen, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Generate a key-encryption key (KEK) from input keying material using a key derivation function (KDF).
[out] | lpOutput | byte array to be filled with output key material (OKM/KEK) (cannot be NULL). |
[in] | nOutputLen | required size of the output key in bytes (must be greater than zero). |
[in] | lpIKM | byte array containing the input key material/shared secret value (denoted variously as IKM/K/Z/ZZ). |
[in] | nIkmLen | length of the input key material in bytes. |
[in] | lpInfo | byte array containing the optional SharedInfo (otherInfo/key derivation parameter/kdp). |
[in] | nInfoLen | length of the SharedInfo in bytes. |
[in] | szParams | (optional) parameters. Set as the empty string "" for defaults. Otherwise include a set of attribute-value pairs separated by a semi-colon ";" to set options from the following
|
[in] | nOptions | Option flags. Select one of:PKI_KDF_X963 to use the the ANSI-X9.63-KDF key derivation function (default)PKI_KDF_HKDF to use the HMAC-based Key Derivation Function (HKDF) from RFC 5869PKI_KDF_KDF2 to use KDF2 from ANSI-X9.44. New in [v23.0]PKI_KDF_KDF3 to use KDF3 from ANSI-X9.44. New in [v23.0]and select one hash algorithm to use with the key derivation function: PKI_HASH_SHA1 (0) to use the SHA-1 hash algorithm (default - CAUTION)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithm [minimum recommended]PKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithm |
The ANSI-X9.63-KDF key derivation function is described in section 3.6.1 of [SEC1]. The HMAC-based Key Derivation Function (HKDF) is described in [RFC5869]. KDF2 and KDF3 are described in ANSI X9.44 [X9-44].
long KDF_ForCms | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const void * | lpZZ, | ||
long | nZzLen, | ||
const void * | lpUkm, | ||
long | nUkmLen, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Generate a key-encryption key (KEK) for ECDH key exchange in a CMS EnvelopedData object.
[out] | lpOutput | byte array to be filled with output key material (OKM/KEK). |
[in] | nOutputLen | required size of the output key in bytes. |
[in] | lpZZ | byte array containing the input key material/shared secret value (denoted variously as ZZ/Z/K/IKM). |
[in] | nZzLen | length of the shared secret material in bytes. |
[in] | lpUkm | (optional) byte array containing user key material (ukm) |
[in] | nUkmLen | length of user key material (ukm) in bytes. |
[in] | szParams | (optional) parameters. Not used in this version. Set as the empty string "". |
[in] | nOptions | Option flags. Select one of:PKI_KDF_X963 to use the the ANSI-X9.63-KDF key derivation function (default) orPKI_KDF_HKDF to use the HMAC-based Key Derivation Function (HKDF) from RFC 5869;and select one hash algorithm to use with the key derivation function: PKI_HASH_SHA1 (0) to use the SHA-1 hash algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithm [minimum recommended]PKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmand select one option to specify the key wrap algorithm (no default): PKI_KWRAP_3DES to use cms3DESwrap PKI_KWRAP_AES128 to use aes128-wrap PKI_KWRAP_AES192 to use aes192-wrap PKI_KWRAP_AES256 to use aes256-wrap |
Note the behaviour of this function is different from KDF_KeyBytes
as the length of the output is fixed by the key wrap algorithm and is not an arbitrary number. The function returns the number of bytes in the output key material, not zero on success. Specify a zero nOutChars or NULL
for szOutput to find the required number of bytes for the given key wrap algorithm. The output buffer for the output key material lpOutput must have been dimensioned to at least the required length in nOutBytes.
When using ECDH with EnvelopedData, the key-encryption keys are derived using the ECC-CMS-SharedInfo type, described in section 7.2 of [RFC5753] (the SharedInfo input to the KDF is the DER-encoded ECC-CMS-SharedInfo structure).
The processing of the ukm with the HKDF key derivation function is described in section 2.2 of RFC8418.
long OCSP_MakeRequest | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szIssuerCert, | ||
const char * | szCertFileOrSerialNum, | ||
const char * | szExtensions, | ||
long | nOptions | ||
) |
Creates an Online Certification Status Protocol (OCSP) request as a base64 string.
[out] | szOutput | to receive output in base64 format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szIssuerCert | with name of issuer's X.509 certificate file (or base64 representation). |
[in] | szCertFileOrSerialNum | with either the name of X.509 certificate file to be checked or its serial number in hexadecimal format preceded by "#x". |
[in] | szExtensions | Not used. Set as empty string "" or NULL. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
The output is a base64 string suitable for an OCSP request to an Online Certificate Status Manager. The issuer's X.509 certficate must be specified. The certificate to be checked can either be specified directly as a filename or as a serialNumber in hexadecimal format preceded by "#x", e.g. "#x01deadbeef"
. If the latter format is used, it must be in hexadecimal format, so the serial number 10 would be passed as "#x0a"
. It is an error (NO_MATCH_ERROR
) if the issuer's name of the certificate to be checked does not match the subject name of the issuer's certificate. The default hash algorithm is SHA-1. Most Online Certificate Status Managers should accept MD5 and SHA-1. Other hash algorithms may not be accepted.
One way to obtain a response is to paste the URL in the address bar of a web browser to return the status information. The base64 value produced by this function should first be URL-encoded (i.e. "/" replaced by "%2F", "+" replaced by "%2B", and "=" by "%3D"). For example, typing in the Firefox browser URL box
http://ocsp.comodoca.com/MFIwUDBOMEwwSjAJBgUrDgMCGgUABBRtl6lMY2%2BiPob4twryIF%2BFfgUdvwQUK8NGq7oOyWUqRtF5R8Ri4uHa%2FLgCEQD7xyMijIyAItiFkiPe5wZg
should offer to save a file with a name like MFIwUDBOME...
. This contains the response, which is a binary file that can be examined using the OCSP_ReadResponse() function.
long OCSP_ReadResponse | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szResponseFile, | ||
const char * | szIssuerCert, | ||
const char * | szExtensions, | ||
long | nOptions | ||
) |
Reads a response to an Online Certification Status Protocol (OCSP) request and outputs the main results in text form.
[out] | szOutput | to receive output as ordinary text. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szResponseFile | with the name of the file containing the response data in BER format. |
[in] | szIssuerCert | (optional) with name of issuer's X.509 certificate file (or base64 representation). |
[in] | szExtensions | Not used. Set as empty string "" or NULL. |
[in] | nOptions | Option flags. For future use. Specify zero. |
The output is a text string outlining the main results in the response data. Typical result strings are:
Successful response: Produced at 2010-03-18T00:09:28Z CertStatus=good SerialNumber=00FBC723228C8C8022D8859223DEE70660
Successful response: Produced at 2010-03-27T12:13:11Z CertStatus=revoked at 2009-05-29T19:23:16Z SerialNumber=7FFED5D77FD1AEEC63716CA220B098A9
malformedRequest.
unauthorized.
Note that a revoked certificate will still result in a "Successful response".
The issuer's X.509 certficate szIssuerCert is optional. If provided, it will be used to check the signature on the OCSP reponse and and an error will result if the signature is not valid. CAUTION: For some CAs (e.g. VeriSign) the key used to sign the OCSP response is not the same as the key in the issuer's certificate, so specifying the issuer's certificate in this case will result in a signature error. If you can separately obtain the certificate used to sign the OCSP response, then specify this as the szIssuerCert; otherwise leave as the empty string ""
.
long PAD_BytesBlock | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
long | nBlkLen, | ||
long | nOptions | ||
) |
Creates an input block suitably padded for encryption by a block cipher in ECB or CBC mode.
[out] | lpOutput | array to be filled with padded encryption block. |
[in] | nOutBytes | specifying the size of the output array in bytes. |
[in] | lpInput | array containing the plaintext bytes to be padded. |
[in] | nInputLen | specifying the length of the plaintext in bytes. |
[in] | nBlkLen | specifying the cipher block length in bytes (8 or 16). |
[in] | nOptions | option flags. Select one of:PKI_PAD_DEFAULT (0) to use the default PKCS5 paddingPKI_PAD_PKCS5 to use Pkcs5Padding (same as default)PKI_PAD_1ZERO to use OneAndZeroesPaddingPKI_PAD_AX923 to use the padding scheme described in ANSI X9.23PKI_PAD_W3C to use the padding scheme described in W3C <https://www.w3.org/TR/xmlenc-core1/#sec-Padding> |
NULL
in C or ByVal 0&
in VBA) then the required number of bytes will be returned. The output is always longer than the input. Only block lengths of 8 or 16 bytes are supported. long PAD_HexBlock | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szInput, | ||
long | nBlkLen, | ||
long | nOptions | ||
) |
Creates a hex-encoded input block suitably padded for encryption by a block cipher in ECB or CBC mode.
[out] | szOutput | to receive the hexadecimal-encoded padded encryption block. |
[in] | nOutChars | specifying the maximum number of characters in szOutput. |
[in] | szInput | containing the hexadecimal-encoded data to be padded. |
[in] | nBlkLen | specifying the cipher block length in bytes (8 or 16). |
[in] | nOptions | option flags. Select one of:PKI_PAD_DEFAULT (0) to use the default PKCS5 paddingPKI_PAD_PKCS5 to use Pkcs5Padding (same as default)PKI_PAD_1ZERO to use OneAndZeroesPaddingPKI_PAD_AX923 to use the padding scheme described in ANSI X9.23PKI_PAD_W3C to use the padding scheme described in W3C <https://www.w3.org/TR/xmlenc-core1/#sec-Padding> |
The output will be padded according to the convention specified in nOptions.
The output is always longer than the input. Only block lengths of 8 or 16 bytes are supported.
long PAD_UnpadBytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
long | nBlkLen, | ||
long | nOptions | ||
) |
Removes the padding from an encryption block.
[out] | lpOutput | array to be filled with the output. |
[in] | nOutBytes | specifying the size of the output array in bytes. |
[in] | lpInput | array containing the padded data. |
[in] | nInputLen | specifying the length of the input in bytes. |
[in] | nBlkLen | specifying the cipher block length in bytes (8 or 16). |
[in] | nOptions | option flags. Select one of:PKI_PAD_DEFAULT (0) to use the default PKCS5 paddingPKI_PAD_PKCS5 to use Pkcs5Padding (same as default)PKI_PAD_1ZERO to use OneAndZeroesPaddingPKI_PAD_AX923 to use the padding scheme described in ANSI X9.23PKI_PAD_W3C to use the padding scheme described in W3C <https://www.w3.org/TR/xmlenc-core1/#sec-Padding> |
If nOutBytes is set to zero or lpOutput set to 0 (or NULL
in C or ByVal 0&
in VBA) then the required number of bytes will be returned. The output is always shorter than the input. Only block lengths of 8 or 16 bytes are supported.
long PAD_UnpadHex | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szInput, | ||
long | nBlkLen, | ||
long | nOptions | ||
) |
Removes the padding from a hex-encoded encryption block.
[out] | szOutput | to receive the hexadecimal-encoded output. |
[in] | nOutChars | specifying the maximum number of characters in szOutput. |
[in] | szInput | containing the hexadecimal-encoded padded data. |
[in] | nBlkLen | specifying the cipher block length in bytes (8 or 16). |
[in] | nOptions | option flags. Select one of:PKI_PAD_DEFAULT (0) to use the default PKCS5 paddingPKI_PAD_PKCS5 to use Pkcs5Padding (same as default)PKI_PAD_1ZERO to use OneAndZeroesPaddingPKI_PAD_AX923 to use the padding scheme described in ANSI X9.23PKI_PAD_W3C to use the padding scheme described in W3C <https://www.w3.org/TR/xmlenc-core1/#sec-Padding> |
The output is always shorter than the input. Only block lengths of 8 or 16 bytes are supported. Note that it is a valid result for szOutput to be an empty string.
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
When using the VBA wrapper function padUnpadHex
and there is an error, then the input is returned unchanged. The user should check for this and signal an error. See the VBA wrapper example below.
long PBE_Kdf2 | ( | unsigned char * | lpOutput, |
long | nOutputLen, | ||
const unsigned char * | lpPwd, | ||
long | nPwdLen, | ||
const unsigned char * | lpSalt, | ||
long | nSaltLen, | ||
long | nCount, | ||
long | nOptions | ||
) |
Derives a key of any length from a password using the PBKDF2 algorithm from PKCS #5.
[out] | lpOutput | array to be filled with derived key. |
[in] | nOutputLen | specifying the size of the required key in bytes. |
[in] | lpPwd | array containing the password. |
[in] | nPwdLen | specifying the length of the password in bytes. |
[in] | lpSalt | array containing the salt. |
[in] | nSaltLen | specifying the length of the salt in bytes. |
[in] | nCount | specifying the required iteration count. |
[in] | nOptions | Option flags. Select one of: HMAC with: PKI_HASH_SHA1 (0) to use the SHA-1 hash algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
abDerivedKey()
must have been dimensioned to at least the required length. long PBE_Kdf2Hex | ( | char * | szOutput, |
long | nMaxChars, | ||
long | dkBytes, | ||
const char * | szPwd, | ||
const char * | szSaltHex, | ||
long | nCount, | ||
long | nOptions | ||
) |
Derives a key of any length from a password using the PBKDF2 algorithm from PKCS #5 with the salt and output derived key encoded in hexadecimal.
[out] | szOutput | to receive the hexadecimal-encoded derived key. |
[in] | nMaxChars | specifying the maximum number of characters in szOutput. |
[in] | dkBytes | specifying the size of the required key in bytes. |
[in] | szPwd | containing the password. |
[in] | szSaltHex | containing the salt in hex format. |
[in] | nCount | specifying the required iteration count. |
[in] | nOptions | Option flags. Select one of: HMAC with: PKI_HASH_SHA1 (0) to use the SHA-1 hash algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
Len(strOutput)
). ANSI C users must add one to this value when allocating memory. The seed szSaltHex is specified in hex format and can be any even number of hex digits in length. The password szPassword is normal text, not hexadecimal. long PBE_Scrypt | ( | unsigned char * | lpDerivedKey, |
long | nKeyLen, | ||
const unsigned char * | lpPwd, | ||
long | nPwdLen, | ||
const unsigned char * | lpSalt, | ||
long | nSaltLen, | ||
long | nParamN, | ||
long | nParamR, | ||
long | nParamP, | ||
long | nOptions | ||
) |
Derives a key of any length from a password using the SCRYPT algorithm.
[out] | lpDerivedKey | Byte array to be filled with derived key. |
[in] | nKeyLen | size of required key in bytes. |
[in] | lpPwd | Byte array containing the password. |
[in] | nPwdLen | length of the password in bytes. |
[in] | lpSalt | Byte array containing the salt. |
[in] | nSaltLen | length of the salt in bytes. |
[in] | nParamN | CPU/Memory cost parameter N ("costParameter" ) a number greater than one and a power of 2. |
[in] | nParamR | Block size r ("blockSize" ) |
[in] | nParamP | Parallelization parameter p ("parallelizationParameter" ) |
[in] | nOptions | Option flags: not used in this release. Specify zero. |
The output buffer for the derived key abDerivedKey must have been dimensioned to at least the required length nKeyLen in bytes.
long PBE_ScryptHex | ( | char * | szOutput, |
long | nMaxChars, | ||
long | dkBytes, | ||
const char * | szPwd, | ||
const char * | szSaltHex, | ||
long | nParamN, | ||
long | nParamR, | ||
long | nParamP, | ||
long | nOptions | ||
) |
Derives a key of any length from a password using the SCRYPT algorithm with the salt and derived key encoded in hexadecimal.
[out] | szOutput | to receive the hexadecimal-encoded derived key. |
[in] | nMaxChars | specifying the maximum number of characters in szOutput. |
[in] | dkBytes | specifying the size of the required key in bytes. |
[in] | szPwd | containing the password (as normal text). |
[in] | szSaltHex | containing the salt in hex format. |
[in] | nParamN | CPU/Memory cost parameter N ("costParameter" ) a number greater than one and a power of 2. |
[in] | nParamR | Block size r ("blockSize" ) |
[in] | nParamP | Parallelization parameter p ("parallelizationParameter" ) |
[in] | nOptions | Option flags: not used in this release. Specify zero. |
Len(strOutput)
). The seed szSaltHex is specified in hex format and can be any even number of hex digits in length. The password szPassword is normal text, not hexadecimal. long PEM_FileFromBinFile | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const char * | szHeader, | ||
long | nLineLen | ||
) |
Creates a PEM file from a binary file .
[in] | szFileOut | with name of output file to be created. |
[in] | szFileIn | with the filename of the binary file to be converted. |
[in] | szHeader | specifying the header to be used. Leave empty to omit the PEM header and footer. |
[in] | nLineLen | the maximum length of a line in the resulting PEM file (default = 64 characters). |
A PEM file is a text file containing encapsulated base64 data of the form
-----BEGIN FOO BAR----- MIAGCSqGSIb3DQEHA... -----END FOO BAR-----
The label in the header between "BEGIN "
and the following five dash characters "-----"
is set using the szHeader parameter. In the above example, strHeader="FOO BAR"
. You are free to use whatever word or words you like. In this Toolkit, we make no checks that the content of the file matches the header. However, other applications may.
Here is a list of commonly-used headers for PKI-related files.
PEM Header | Type of file | Typical file extensions | Comment |
---|---|---|---|
CERTIFICATE | X.509 certificate | .cer,.der,.pem,.crt | Should contain exactly one certificate |
CERTIFICATE REQUEST | PKCS#10 certificate signing request | .csr,.p10 | |
X509 CRL | X.509 certificate revocation list | .crl | |
PKCS12 | PFX file to PKCS#12 | .p12,.pfx | |
ENCRYPTED PRIVATE KEY | PKCS#8 key | .p8e,.key,(.epk) | Our default private key format |
RSA PUBLIC KEY | PKCS#1 public key | .p1,.pub | Our default public key format |
PUBLIC KEY | SubjectPublicKeyInfo | | OpenSSL format (PKI_KEY_FORMAT_SSL ) |
PRIVATE KEY | Unencrypted PKCS#8 private key info | .p8,.pri,.key | Our private key info format |
RSA PRIVATE KEY | Unencrypted PKCS#1 private key | | OpenSSL format (PKI_KEY_FORMAT_SSL ) |
PKCS7 | CMS object to PKCS#7 | .p7m,.p7s,.p7c,.p7b,.p7z | Used by OpenSSL |
PKCS #7 SIGNED DATA | ditto | | Used by Thawte for Microsoft users |
NETSCAPE CERTIFICATE CHAIN | "certs-only" PKCS#7 | .p7c,.p7b | Used by Thawte for Netscape users |
Update April 2015: see RFC 7468 "Textual Encodings of PKIX, PKCS, and CMS Structures" [RFC7468] for more definitive rules and recommendations on this subject.
long PEM_FileFromBinFileEx | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const char * | szHeader, | ||
long | nLineLen, | ||
long | nOptions | ||
) |
Creates a PEM file from a binary file with extended options.
[in] | szFileOut | with name of output file to be created. |
[in] | szFileIn | with the filename of the binary file to be converted. |
[in] | szHeader | specifying the header to be used. Leave empty to omit the PEM header and footer. |
[in] | nLineLen | the maximum length of a line in the resulting PEM file (default = 64 characters). |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default optionsPKI_KEY_FORMAT_SSL to create the output file with Unix/SSL line endings (default = Windows CR-LF line endings) |
long PEM_FileToBinFile | ( | const char * | szFileOut, |
const char * | szFileIn | ||
) |
Converts the contents of a PEM file into a binary file.
[in] | szFileOut | with name of output file to be created. |
[in] | szFileIn | with the filename of the PEM-encoded file to be converted. |
-----BEGIN FOO BAR----- MIAGCSqGSIb3DQEHA... -----END FOO BAR-----
long PFX_MakeFile | ( | const char * | szFileOut, |
const char * | szCertList, | ||
const char * | szEpkFile, | ||
const char * | szPassword, | ||
const char * | szFriendlyName, | ||
long | nOptions | ||
) |
Creates a simple PFX (PKCS-12) file from an X.509 certificate and (optional) encrypted private key file.
[in] | szFileOut | name of output file to be created. |
[in] | szCertList | (required) filename of the subject's X.509 certificate (or a string containing the certificate in base64 representation) followed by optional extra certificates to be included separated by a semicolon (; ). |
[in] | szEpkFile | filename of the subject's pkcs-8 encrypted private key (or a string containing the key in PEM format). Pass an empty string "" to exclude the private key. |
[in] | szPassword | password for the encrypted private key. |
[in] | szFriendlyName | friendly name identification for the subject (optional). |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default options: re-encrypt private key with "TripleDES-SHA1", encrypt certificate with 40-bit RC2, output in DER binary form.PKI_PFX_CLONE_KEY to store the private key in the exact form of the pkcs-8 input file (default is to re-encrypt with 3DES)Add one of the following: PKI_PFX_PLAIN_CERT to store the certificate in unencrypted form (default is encrypted)PKI_PFX_STRONG_CERT to encrypt the certificate with "stronger" TripleDES-SHA1 (default is "weak" 40-bit RC2)Or, new in [v20.5], to override the above encryption options, use instead PKI_PFX_AES256_SHA256 to encrypt both the private key and certificate using "AES256-SHA256"Then add any of these options: PKI_KEY_FORMAT_PEM to create the output file in PEM format (default is DER-encoded binary)PKI_PFX_ALT_FORMAT to create a PFX file with the exact peculiarities used by Microsoft (default is OpenSSL format) |
;
). The first certificate in the list must be the matching certificate for the private key, if included. The default behaviour is to save the certificate(s) encrypted using the "standard" weak 40-bit RC2 encryption (pbeWithSHAAnd40BitRC2-CBC
) as used (until recently) by Windows Certificate Manager and OpenSSL, and the private key is re-encrypted using the "standard" TripleDES-SHA1 algorithm (pbeWithSHAAnd3-KeyTripleDES-CBC
).[New in v12.3] Use the PKI_PFX_STRONG_CERT
option to encrypt the certificate with "stronger" Triple DES, the same as the default key encryption algorithm. The PKI_PFX_PLAIN_CERT
option takes precedence.
[New in v20.5] Use the PKI_PFX_AES256_SHA256
option to encrypt both the private key and certificate using "AES256-SHA256".
The szFriendlyName parameter is optional. To exclude the private key just pass an empty szKeyFile parameter.
To help users of a certain brain-dead web service in Mexico which cannot cope with anything else, the default file format is the exact format that would be created by OpenSSL. If you really need Microsoft's peculiaritiesλ, then add the PKI_PFX_ALT_FORMAT
option flag.
Any form of PKCS-12 file created by this function should be importable into Windows Certificate Manager/Outlook (use a .pfx extension for the output file) and Mozilla/Firefox (use a .p12 extension). The PKCS-12 standard is notorious for its peculiarities - see PFX - How Not to Design a Crypto Protocol/Standard [GUTPFX]. If you do not have success with your target application, try changing the options. In particular, using the PKI_PFX_CLONE_KEY
option may cause problems if the target application cannot decrypt the super-secure algorithm you've used to protect your private key (error messages about a missing cryptographic provider are a clue here). That's why the default behaviour is to re-encrypt using the "standard" algorithm.
If you specify both a certificate and a private key, their RSA keys must match or a PKI_NO_MATCH_ERROR
error will occur. The PKCS-12 file will be protected using the specified szPassword, which must match the password for the encrypted private key file, if included. The password is optional for the case where there is just a certificate, but is required if you need the certificate to be encrypted. If you don't use a password for a cert-only file, just enter an empty password when importing the PFX into Windows.
If you use the PKI_KEY_FORMAT_PEM
option, the output file will be in PEM format with the first line "-----BEGIN PKCS12-----"
. Be warned, Windows does not recognise such a file as a valid PFX/PKCS-12 format!
λ The difference between the OpenSSL and Microsoft forms is that the Microsoft form has a "preferredAbsent" NULL parameter added to the message digest object for "sha1" and uses 8 instead of 20 bytes for the MacData salt. Both combinations are perfectly valid according to the PKCS12 specification.
long PFX_VerifySig | ( | const char * | szFileName, |
const char * | szPassword, | ||
long | nOptions | ||
) |
Verifies the signature in a pkcs-12 file.
[in] | szFileName | specifies the PKCS-12 filename to be checked. |
[in] | szPassword | containing the password. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
[New in v3.8] If there is no MacData signature in the PFX file and the supplied szPassword is empty, it will consider that to be a "valid" signature and return zero.
long PKI_CompileTime | ( | char * | szOutput, |
long | nOutChars | ||
) |
Retrieves the date and time the toolkit executable was last compiled.
[out] | szOutput | to receive the date and time string. |
[in] | nOutChars | specifying the maximum length of the string to be copied. |
long PKI_ErrorCode | ( | void | ) |
Returns the error code of the first error that occurred when calling the last function.
For example, a call to CMS_MakeEnvData with one invalid X.509 certificate out of three would return 2 indicating two successful recipients. A call to PKI_ErrorCode()
will indicate the error code for the invalid certificate. PKI_LastError() should have a more detailed error message.
long PKI_ErrorLookup | ( | char * | szOutput, |
long | nOutChars, | ||
long | nErrCode | ||
) |
Retrieves the error message associated with a given error code.
[out] | szOutput | to receive error message. |
[in] | nOutChars | specifying the maximum length of the string to be copied. |
[in] | nErrCode | specifying the error code for which the message is required. |
The error message will never be longer than 127 characters (PKI_MAX_ERRORLOOKUP_CHARS
).
long PKI_FormatErrorMessage | ( | char * | szOutput, |
long | nOutChars, | ||
long | nErrCode, | ||
const char * | szUserMsg | ||
) |
Return a formatted error message string for the last error.
[out] | szOutput | Buffer to receive output string. |
[in] | nOutChars | Maximum length of output string in bytes. |
[in] | nErrCode | Error code returned by last call (or zero if no code available). |
[in] | szUserMsg | Optional user message to add. |
ERROR (11): Value out of range (OUT_OF_RANGE_ERROR) ERROR: User message! (11): Value out of range (OUT_OF_RANGE_ERROR) ERROR (21): No match found (NO_MATCH_ERROR): (1) Cannot open input file (OPEN_ERROR): Private key does not match any certificate in list
The equivalent functions in other languages are written independently and will give similar but not identical outputs.
The error message will never be longer than 1023 characters plus the length of any user message. In the raw ANSI C function you can query the expected length, but it is recommended to write directly to a fixed size buffer, as in the example below.
long PKI_LastError | ( | char * | szOutput, |
long | nOutChars | ||
) |
Retrieves the last error message set by the toolkit.
[out] | szOutput | to receive last error message. |
[in] | nOutChars | specifying the maximum length of the string to be copied. |
long PKI_LicenceType | ( | long | nOptions | ) |
Returns the ASCII value of the licence type.
[in] | nOptions | not used in this release. Specify zero. |
long PKI_ModuleInfo | ( | char * | szOutput, |
long | nOutChars, | ||
long | nOptions | ||
) |
Get additional information about the core DLL module.
[out] | szOutput | Buffer to receive output string. |
[in] | nOutChars | Maximum length of output string in bytes. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
long PKI_ModuleName | ( | char * | szOutput, |
long | nOutChars, | ||
long | nOptions | ||
) |
Retrieves the name of the current process's module.
[out] | szOutput | to receive the name of the module. |
[in] | nOutChars | specifying the maximum length of the string to be copied. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
If using the Win32 DLL in the system folder on a 64-bit system, Windows will return "C:\WINDOWS\SYSTEM32\diCrPKI.dll"
when the DLL file path is actually "C:\WINDOWS\SYSWOW64\diCrPKI.dll"
. Use PKI_Platform
to find out exactly which DLL is being used.
long PKI_Platform | ( | char * | szOutput, |
long | nOutChars | ||
) |
Gets the platform the core DLL was compiled for.
[out] | szOutput | to receive output, either "Win32" or "X64". |
[in] | nOutChars | specifying the maximum length of the string to be copied. |
long PKI_PowerUpTests | ( | long | nOptions | ) |
Carries out on demand the full set of power-up tests automatically performed by the toolkit when first powered up (i.e.
when the DLL is first attached to the process).
[in] | nOptions | option flags: not used in this release. Specify zero. |
long PKI_Version | ( | void * | nReserved1, |
void * | nReserved2 | ||
) |
Retrieves the release version number.
[in] | nReserved1 | ignored in version 2.8 and above - use 0. |
[in] | nReserved2 | ignored in version 2.8 and above - use 0. |
long PRF_Bytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const void * | lpMessage, | ||
long | nMsgLen, | ||
const void * | lpKey, | ||
long | nKeyLen, | ||
const char * | szCustom, | ||
long | nOptions | ||
) |
Generate output bytes using a pseudorandom function (PRF).
[out] | lpOutput | byte buffer to receive the output. |
[in] | nOutBytes | size of output buffer in bytes. |
[in] | lpMessage | byte array containing the input data. |
[in] | nMsgLen | length of the input data in bytes. |
[in] | lpKey | byte array containing the key. |
[in] | nKeyLen | length of the key in bytes. |
[in] | szCustom | customization string (optional). |
[in] | nOptions | Option flags. Select one of:PKI_KMAC_128 to use KMAC128 (KMAC with SHAKE128)PKI_KMAC_256 to use KMAC256 (KMAC with SHAKE256). |
""
. long PWD_Prompt | ( | char * | szPassword, |
long | nPwdLen, | ||
const char * | szCaption | ||
) |
Prompts for a password in a dialog box.
[out] | szPassword | to receive the password entered by the user. |
[in] | nPwdLen | specifying the maximum length of the string to be received. |
[in] | szCaption | specifying a caption for the dialog box (optional). |
The password string is limited to 255 characters. It's up to the developer to protect the secrecy of the password once it's been entered: see WIPE_Data()
.
long PWD_PromptEx | ( | char * | szPassword, |
long | nPwdLen, | ||
const char * | szCaption, | ||
const char * | szPrompt, | ||
long | nOptions | ||
) |
Prompts for a password in a dialog box with option to change prompt wording.
[out] | szPassword | to receive the password entered by the user. |
[in] | nPwdLen | specifying the maximum length of the string to be received. |
[in] | szCaption | specifying a caption for the dialog box (optional). |
[in] | szPrompt | specifying the prompt (default="Enter password:"). |
[in] | nOptions | option flags: not used in this release. Specify zero. |
PWD_Prompt()
. long RNG_Bytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const void * | lpSeed, | ||
long | nSeedLen | ||
) |
Generates a random set of byte data suitable for cryptographic keys.
[out] | lpOutput | array to receive the random data. |
[in] | nOutBytes | specifying the required length in bytes. |
[in] | lpSeed | containing "user-supplied entropy" to be used by the random number generator. Specify an empty string ("") or NULL to ignore. |
[in] | nSeedLen | specifying the length of the seed string. |
The length of the seed must be specified (set nSeedLen as zero to ignore).
If the RNG fails its FIPS-140 continuous test, the DLL process will be terminated. There is no option to avoid this, but the chances of such a failure under normal conditions are absolutely miniscule
long RNG_BytesWithPrompt | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const char * | szPrompt, | ||
long | nOptions | ||
) |
Generates a random set of byte data suitable for cryptographic keys with a prompt for the user to enter random keystrokes and mouse movements.
[out] | lpOutput | array to receive the random data. |
[in] | nOutBytes | specifying the required length in bytes. |
[in] | szPrompt | specifying an (optional) prompt for the dialog. Specify an empty string ("") or NULL to use the default dialog. |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default optionsPKI_RNG_STRENGTH_112 to make user generate an estimated 112 bits of security (default)PKI_RNG_STRENGTH_128 to make user generate an estimated 128 bits of security PKI_RNG_STRENGTH_192 to make user generate an estimated 192 bits of security PKI_RNG_STRENGTH_256 to make user generate an estimated 256 bits of security |
long RNG_Guid | ( | char * | szOutput, |
long | nOutChars, | ||
long | nOptions | ||
) |
Generate a random 36-character Global Unique IDentifier (GUID) string.
[out] | szOutput | String buffer to receive output. |
[in] | nOutChars | Maximum number of characters to be received. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
A Global Unique IDentifier
(GUID) is also called a version 4 Universally Unique IDentifier
(UUID) and is defined in section 4.4 of [RFC4122]. The output is always a 36-character string of the form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" where 'x' is a hexadecimal digit [0-9a-f]
. The constant PKI_RNG_GUID_CHARS
equal to 36 is defined for convenience. It is an error (SHORT_BUF_ERROR
) if the output buffer is too short.
long RNG_Initialize | ( | const char * | szSeedFile, |
long | nOptions | ||
) |
Initializes the RNG generator with a seed file.
[in] | szSeedFile | specifying a seed file. May be the empty string "" . |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default optionsPKI_RNG_NO_INTEL_DRNG to turn off support for Intel(R) DRNG for the current session. |
Intel(R) DRNG support: [New in v22.1] Pass an empty string ""
for szSeedFile to query support for Intel(R) Digital Random Number Generator (DRNG) on your system (and add an extra 256 bits of entropy, if available). If supported, the return value is a positive integer (1,2,3), otherwise it returns the error code PRNG_ERR_NOTAVAIL
(-214). See Intel(R) DRNG.
Alternatively, use the option PKI_RNG_NO_INTEL_DRNG
to turn off support for Intel(R) DRNG for the current session. You might use this if calls to Intel(R) DRNG are causing problems on your system.
long RNG_MakeSeedFile | ( | const char * | szSeedFile, |
const char * | szPrompt, | ||
long | nOptions | ||
) |
Creates a new seed file suitable for use with RNG_Initialize().
[in] | szSeedFile | specifying the seed file to be created. |
[in] | szPrompt | specifying an (optional) prompt for the dialog. Specify an empty string ("") or NULL to use the default dialog. |
[in] | nOptions | option flags:PKI_DEFAULT (0) for default optionsPKI_RNG_STRENGTH_112 to make user generate an estimated 112 bits of security (default)PKI_RNG_STRENGTH_128 to make user generate an estimated 128 bits of security PKI_RNG_STRENGTH_192 to make user generate an estimated 192 bits of security PKI_RNG_STRENGTH_256 to make user generate an estimated 256 bits of security |
PkiMkRngSeed.exe
, provided in the distribution to make a new seed file [updated in v22.1]. long RNG_Number | ( | long | nLower, |
long | nUpper | ||
) |
Returns an integer selected at random between specified limits.
[in] | nLower | specifying a lower limit. |
[in] | nUpper | specifying an upper limit. |
long RNG_Test | ( | const char * | szFileOut, |
long | nOptions | ||
) |
Carries out a NIST SP800-90 health check and FIPS140-2 statistical tests on the random number generator.
[in] | szFileOut | (optional) specifying the test output file to be created. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
""
) or NULL szFileName to avoid creating an output file and just carry out the tests. The statistical tests have since been removed from FIPS-140-2, but we do them anyway. If any tests fail, a nonzero error code will be returned. long RNG_TestDRBGVS | ( | char * | szOutput, |
long | nMaxChars, | ||
long | nReturnedBitsLen, | ||
const char * | szEntropyInput, | ||
const char * | szNonce, | ||
const char * | szPersonalizationString, | ||
const char * | szAdditionalInput1, | ||
const char * | szEntropyReseed, | ||
const char * | szAdditionalInputReseed, | ||
const char * | szAdditionalInput2, | ||
long | nOptions | ||
) |
Test the RNG for conformance to NIST SP800-90A using the relevant test specified in DRBGVS.
[out] | szOutput | to receive the ReturnedBits in hexadecimal format. |
[in] | nMaxChars | specifying the maximum number of hexadecimal characters to be received. |
[in] | nReturnedBitsLen | specifying the number of bits to be returned from each call to the generate function in the test. |
[in] | szEntropyInput | containing the EntropyInput value in hex format. |
[in] | szNonce | containing the Nonce value in hex format. |
[in] | szPersonalizationString | containing the PersonalizationString value in hex format. |
[in] | szAdditionalInput1 | containing the first AdditionalInput value in hex format. |
[in] | szEntropyReseed | containing the EntropyReseed value in hex format. |
[in] | szAdditionalInputReseed | containing the AdditionalInputReseed value in hex format. |
[in] | szAdditionalInput2 | containing the second AdditionalInput value in hex format. |
[in] | nOptions | Option flags: not used in this release. Specify zero. |
HMAC_DRBG SHA-512
without prediction resistance. Use the empty string ""
to pass a zero-length input. All hex strings must have an even number of characters. long RNG_UpdateSeedFile | ( | const char * | szSeedFile, |
long | nOptions | ||
) |
Updates an RNG seed file.
[in] | szSeedFile | specifying the seed file to be updated. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
long RSA_CheckKey | ( | const char * | szKeyString, |
long | nOptions | ||
) |
Checks if an RSA key is valid.
[in] | szKeyString | containing the RSA public or private key in internal format |
[in] | nOptions | option flags: not used in this release. Specify zero. |
long RSA_DecodeMsg | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
long | nOptions | ||
) |
Decodes an EME or EMSA encoded message block according to PKCS#1 (EME = Encoding Method for Encryption, EMSA = Encoding Method for Signature with Appendix).
[out] | lpOutput | array to receive the decoded output. |
[in] | nOutBytes | specifying the maximum length of the output array. |
[in] | lpInput | array containing the data to be decoded. |
[in] | nInputLen | specifying the number of bytes in the input. |
[in] | nOptions | option flags. Include one of the following:-PKI_EME_PKCSV1_5 (0) to decode an 'Encoded Message for Encryption' block using PKCS#1 v1.5 method (default)PKI_EME_OAEP to decode an 'Encoded Message for Encryption' block using OAEP methodPKI_EMSIG_PKCSV1_5 to decode an ‘Encoded Message for Signature’ block using PKCS#1 v1.5 method |
If you have selected PKI_EMSIG_PKCSV1_5
, then you can add:
PKI_EMSIG_DIGINFO
to decode an 'Encoded Message for Signature' block and output the whole DigestInfo
data instead of just the message digest.
If you have selected PKI_EME_OAEP
, then add one of these options to match the hash function used for EME-OAEP encoding:
PKI_HASH_SHA1
(0) to use SHA-1 (default).
PKI_HASH_SHA224
to use SHA-224
PKI_HASH_SHA256
to use SHA-256
PKI_HASH_SHA384
to use SHA-384
PKI_HASH_SHA512
to use SHA-512
and, optionally, add:-
PKI_MGF_MGF1SHA1
to force the MGF hash function to be SHA-1 (default = same as encoding hash function set above)
The encoding hash function and MGF hash function must match the hash functions used to encode the message.
Alternatively, ignore all the above and use the specialist option
PKI_EMSIG_ISO9796
to use the ISO9796-1 encoding for a signature. See AUTACK messages and ISO/IEC 9796-1 signatures for more details.
Messages encoded for both encryption and signature using the PKCS#1 v1.5 method are self-contained: that is, they can be decoded with no further information other than the encoded message itself. However, a message encoded using the OAEP method will be assumed by default to have been encoded using the default SHA-1 function for both the encoding hash algorithm and MGF hash algorithm. If you used a different hash function when encoding you need to specify it explicitly in nOptions.
The algorithm RSA-PSS is not available for this function. Use SIG_VerifyData
instead.
The objective is to recover the original message data which is encoded in the block. Use either
nOptions = PKI_EME_PKCSV1_5
or
nOptions = PKI_EME_OAEP
You need to know which algorithm was used to create the block in the first place.
The objective is to verify that the encoded message digest hash matches the message digest hash of the original message.
Note: it is much simpler (and safer) to use the RSA_EncodeMsg()
function on the original message and then compare the result of that with the input block you have here. See Raw RSA Techniques. The options here are included for advanced users.
There are two choices when decoding an EMSA block:
nOptions = PKI_EMSIG_PKCSV1_5
Extract the whole DigestInfo
bytes. Set
nOptions = PKI_EMSIG_PKCSV1_5 + PKI_EMSIG_DIGINFO
You might use this if you come across a hash algorithm that is not supported by this Toolkit. Use this option to recover the entire DigestInfo
and then inspect the bytes to work out what it is, using your knowledge of DER encoding.
Remember that the result of a decode operation for a signature is to compare the hash digest encoded in the signature with an independent digest of the original message. If they match, the signature is verified. To avoid an attacker exploiting flaws in the decoding operation, it is safer just to generate another EMSA block from the message and compare that directly.
long RSA_Decrypt | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const char * | szPrivateKeyFile, | ||
const char * | szPassword, | ||
const char * | szParameters, | ||
long | nOptions | ||
) |
Decrypt a message encrypted using an RSA encryption scheme.
[out] | lpOutput | byte array to receive the decrypted output. |
[in] | nOutBytes | maximum length of the output array. |
[in] | lpInput | byte array containing the data to be decrypted. |
[in] | nInputLen | length of input in bytes. |
[in] | szPrivateKeyFile | specifying the name of the private key file (or a string containing the key in PEM format, or a valid internal private key string). |
[in] | szPassword | Password for encrypted private key, or "" if password is not required. |
[in] | szParameters | For future use. Specify "" . |
[in] | nOptions | option flags. Include one of the following:-PKI_EME_PKCSV1_5 (0) to decrypt using the RSAES-PKCS1-v1_5 encryption scheme (default).PKI_EME_OAEP to decrypt using the RSAES-OAEP encryption scheme. |
If you have selected PKI_EME_OAEP
, then add one of these options to set the hash function used for EME-OAEP encoding:
PKI_HASH_SHA1
(0) to use SHA-1 (default).
PKI_HASH_SHA224
to use SHA-224
PKI_HASH_SHA256
to use SHA-256
PKI_HASH_SHA384
to use SHA-384
PKI_HASH_SHA512
to use SHA-512
and, optionally, add:-
PKI_MGF_MGF1SHA1
to force the MGF hash function to be SHA-1 (default = same as encoding hash function set above)
NULL
) to return the required number of bytes. The output will always be shorter than the input length.For RSA-OAEP you must set the correct options to match the parameters used for the encryption. For more details see RSA encryption and signature schemes.
long RSA_EncodeMsg | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
long | nOptions | ||
) |
Creates an EME or EMSA encoded message block according to PKCS#1 (EME = Encoding Method for Encryption, EMSA = Encoding Method for Signature with Appendix).
[out] | lpOutput | array to receive the encoded output. |
[in] | nOutBytes | specifying the maximum length of the output array. |
[in] | lpInput | array containing the message to be encoded (or the message digest). |
[in] | nInputLen | specifying the number of bytes in the message. |
[in] | nOptions | option flags. Include one of the following:-PKI_EME_PKCSV1_5 (0) to encode for encryption using PKCS#1 v1.5 method (RSAES-PKCS1-v1_5) (default)PKI_EME_OAEP to encode for encryption using OAEP methodPKI_EMSIG_PKCSV1_5 to encode for signature using PKCS#1 v1.5 method (RSASSA-PKCS1-v1_5) |
If you have selected PKI_EMSIG_PKCSV1_5
, then add one of these options to set the hash function for the signature message digest:
PKI_HASH_SHA1
(0) to use SHA-1 (default).
PKI_HASH_SHA224
to use SHA-224
PKI_HASH_SHA256
to use SHA-256
PKI_HASH_SHA384
to use SHA-384
PKI_HASH_SHA512
to use SHA-512
PKI_HASH_MD5
to use MD5 [legacy, not recommended]
PKI_HASH_MD2
to use MD2 [legacy, definitely not recommended]
and, optionally, add:-
PKI_EMSIG_DIGESTONLY
as a flag to pass the message digest only as input to-be-signed (default = pass entire message)
If you have selected PKI_EME_OAEP
, then add one of these options to set the hash function for EME-OAEP encoding:
PKI_HASH_SHA1
(0) to use SHA-1 (default).
PKI_HASH_SHA224
to use SHA-224
PKI_HASH_SHA256
to use SHA-256
PKI_HASH_SHA384
to use SHA-384
PKI_HASH_SHA512
to use SHA-512
and, optionally, add:-
PKI_MGF_MGF1SHA1
to force the MGF hash function to be SHA-1 (default = same as encoding hash function set above)
Alternatively, ignore all the above and use the specialist option
PKI_EMSIG_ISO9796
to use the ISO9796-1 encoding for a signature. See AUTACK messages and ISO/IEC 9796-1 signatures for more details.
Set either
nOptions = PKI_EME_PKCSV1_5
or
nOptions = PKI_EME_OAEP
The default operation PKI_EME_PKCSV1_5
will create an encoded EME message block according to PKCS#1 v1.5. The PKI_EME_OAEP
alternative uses a more secure algorithm (OAEP = Optimal Asymmetric Encryption Padding).
To encode the message "Hello world" ready for signing, use the PKI_EMSIG_PKCSV1_5
option and set
nOptions = PKI_EMSIG_PKCSV1_5 abInput = StrConv("Hello world", vbFromUnicode) nInputLen = UBound(abMessage) - LBound(abMessage) + 1
nOptions = PKI_EMSIG_PKCSV1_5; input = "Hello world"; nInputLen = strlen(input);
If you need to be compatible with a legacy application that uses, say, MD5, add the hash flag to the option
nOptions = PKI_EMSIG_PKCSV1_5 + PKI_HASH_MD5
If you have already computed the message digest in byte array form, then pass this as input and set
nOptions = PKI_EMSIG_PKCSV1_5 + PKI_EMSIG_DIGESTONLY
The algorithm RSA-PSS is not available for this function. Use SIG_SignData
instead.
long RSA_Encrypt | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const unsigned char * | lpInput, | ||
long | nInputLen, | ||
const char * | szPublicKeyFile, | ||
const char * | szParameters, | ||
long | nOptions | ||
) |
Encrypt a short message using RSA encryption.
[out] | lpOutput | byte array to receive the encrypted output. |
[in] | nOutBytes | maximum length of the output array. |
[in] | lpInput | byte array containing the data to be encrypted. |
[in] | nInputLen | length of input in bytes. |
[in] | szPublicKeyFile | specifying the name of the public key file or X.509 certificate (or a string containing the key or certificate in PEM format, or a valid internal public key string). |
[in] | szParameters | For specialist use. Specify "" . See remarks. |
[in] | nOptions | option flags. Include one of the following:-PKI_EME_PKCSV1_5 (0) to encrypt using the RSAES-PKCS1-v1_5 encryption scheme (default).PKI_EME_OAEP to encrypt using the RSAES-OAEP encryption scheme. |
If you have selected PKI_EME_OAEP
, then add one of these options to set the hash function for EME-OAEP encoding:
PKI_HASH_SHA1
(0) to use SHA-1 (default).
PKI_HASH_SHA224
to use SHA-224
PKI_HASH_SHA256
to use SHA-256
PKI_HASH_SHA384
to use SHA-384
PKI_HASH_SHA512
to use SHA-512
and, optionally, add:-
PKI_MGF_MGF1SHA1
to force the MGF hash function to be SHA-1 (default = same as encoding hash function set above)
NULL
) to return the required number of bytes. The output is always the same length in bytes as the RSA modulus, which can be found directly using the RSA_KeyBytes() function.There is a limit on the length of data that can be encrypted. For RSAES-PKCS1-V1_5, nInputLen must not be greater than the key length in bytes (k) minus 11. For RSAES-OAEP, nInputLen must not be greater than k - 2*hLen - 2
, where hLen is the length in bytes of the hash function output. Note this means, for example, that you cannot use SHA-512 with a 1024-bit RSA key with RSAES-OAEP.
The default parameters for RSA-OAEP encoding are
hashAlgorithm = sha1, maskGenAlgorithm = mgf1SHA1 (MGF1 with SHA-1) pSourceAlgorithm =pSpecifiedEmpty (label L is the empty string)
You can change the hash algorithm using nOptions (and by default the MGF1 hash algorithm will be the same), and you can force the MGF1 hash algorithm to be SHA-1. You cannot change the mask generation algorithm (there isn't another!) or the pSourceAlgorithm parameter (i.e. the label is always the empty string). For more details see RSA encryption and signature schemes.
To carry out tests against known test vectors, you can pass a fixed seed value in szParameters. For example, "seed=18b776ea21069d69776a33e96bad48e1dda0a5ef"
. This string must begin with "seed="
and be followed by the seed value in hexadecimal encoding. This must represent a byte array of exactly hLen bytes, the length of the output of the hash function.
long RSA_FromXMLString | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szXmlString, | ||
long | nOptions | ||
) |
Creates an RSA key string in internal format from an XML string.
[out] | szOutput | to receive key data either public or private. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szXmlString | containing the RSA public or private key in XML format |
[in] | nOptions | option flags:PKI_DEFAULT (0) to include the private key, if present (default)PKI_XML_EXCLPRIVATE to exclude the private key even if presentPKI_XML_REQPRIVATE to require the private key to exist in the XML input or fail |
A key string created with this function can be used in the other RSA functions in this toolkit that require a key in "internal" format. Use this function to import an RSA key from another application.
Only US-ASCII characters are supported. The XML data should be well formed and must contain either an RSAKeyValue
or RSAKeyPair
element according to [XMLDSIG] or [XKMS2]. The parser has been designed to be pretty forgiving but don't push it too far.
The first such valid element found in the string will be converted and other data will be ignored. If the XML data only contains the public key elements, the resulting internal string will contain a public key and can be used in the functions in this toolkit that require a public key string. If the XML data contains all the private key elements, the internal string will contain a private key unless the PKI_XML_EXCLPRIVATE
option is used. To convert a private key, all components of the key pair must be present; namely, the <Modulus>
, <Exponent>
, <D>
, <P>
, <Q>
, <DP>
, <DQ>
, and <InverseQ>
elements as specified in [XKMS2]. To allow compatibility with older versions of XKMS out there, the deprecated elements <QINV>
, <PublicExponent>
and <PrivateExponent>
will be accepted.
[New in v20.0] Element names with a prefix, e.g. <ds:Modulus>
, are now accepted.
To make life easier to import RSA key data that exists in hexadecimal format, the user can force the function to decode the data in hexadecimal format instead of base64 by adding an attribute with the value "hexBinary"
to each of the component elements of the RSAKeyValue. For example
<Exponent EncodingType="hexBinary">010001</Exponent>
The attribute name is not important. This practice is not in conformance with any existing W3C standard (that we're aware of, anyway) but is included for convenience where the user is creating the XML file by hand using hex data.
long RSA_GetPrivateKeyFromPFX | ( | const char * | szFileOut, |
const char * | szPfxFile, | ||
long | nOptions | ||
) |
Extracts an encrypted private key from a PKCS-12 PKCS8ShroudedKeyBag, saving the output directly as a new file.
[in] | szFileOut | specifying the filename of the output file to be created. |
[in] | szPfxFile | containing the PFX filename |
[in] | nOptions | option flags: not used in this release. Specify zero. |
pkcs-12-pkcs-8ShroudedKeyBag
found in the PFX file will be extracted and saved directly as a BER-encoded EncryptedPrivateKeyInfo
file. No decryption or other conversion is carried out. long RSA_GetPublicKeyFromCert | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szCertFile, | ||
long | nOptions | ||
) |
Reads a public key from an X.509 certificate into an "internal" public key string.
[out] | szOutput | to receive encoded public key data. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szCertFile | specifying the filename of an X.509 certificate file (or base64 representation). |
[in] | nOptions | option flags: not used in this release. Specify zero. |
Woops! The name of this function is an exception to our usual convention that "Read" means read-into-internal-string and "Get" means extract-and-save-as-a-file. By rights this function should be called "RSA_ReadPublicKeyFromCert". Sorry.
long RSA_KeyBits | ( | const char * | szKeyString | ) |
Returns the length of key in bits given the public or private key string.
[in] | szKeyString | containing the RSA private or public key string. |
long RSA_KeyBytes | ( | const char * | szKeyString | ) |
Returns the length of key in complete bytes (octets) given the public or private key string.
[in] | szKeyString | containing the RSA private or public key string. |
long RSA_KeyHashCode | ( | const char * | szKeyString | ) |
Computes the hash code of an "internal" RSA public or private key string.
[in] | szKeyString | containing the RSA private or public key string in internal format. |
If the key string is invalid, the return value is zero and a nonzero error code will be set (use PKI_ErrorCode
to check). There is a very small chance (one in 4 billion) that a valid key string returns a hash code of zero.
long RSA_KeyMatch | ( | const char * | szPrivateKey, |
const char * | szPublicKey | ||
) |
Verifies that a pair of "internal" RSA private and public key strings are matched.
[in] | szPrivateKey | containing an "internal" RSA private key string. |
[in] | szPublicKey | containing an "internal" RSA public key string. |
long RSA_KeyValue | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyString, | ||
const char * | szFieldName, | ||
long | nOptions | ||
) |
Extracts a base64-encoded RSA key value from internal key string.
[out] | szOutput | string of sufficient length to receive the output |
[in] | nOutChars | specifying the maximum number of characters to be received |
[in] | szKeyString | Public or private key in internal string format |
[in] | szFieldName | Name of field to be extracted: "Modulus" or "Exponent" |
[in] | nOptions | option flags. Set to zero. |
The output is a continuous string of base64 characters suitable for a <RSAKeyValue>
node in an XML-DSIG document.
A typical <RSAKeyValue>
node looks like this:
<RSAKeyValue> <Modulus> 4IlzOY3Y9fXoh3Y5f06wBbtTg94Pt6vcfcd1KQ0FLm0S36aGJtTSb6pYKfyX7PqCUQ8wgL6xUJ5GRPEsu9gyz8 ZobwfZsGCsvu40CWoT9fcFBZPfXro1Vtlh/xl/yYHm+Gzqh0Bw76xtLHSfLfpVOrmZdwKmSFKMTvNXOFd0V18= </Modulus> <Exponent>AQAB</Exponent> </RSAKeyValue>
Use this function to populate the fields <Modulus>
and <Exponent>
for a given RSA key, or to use the values in other computations.
long RSA_MakeKeys | ( | const char * | szPubKeyFile, |
const char * | szEpkFile, | ||
long | nBits, | ||
long | nExpFermat, | ||
long | nTests, | ||
long | nCount, | ||
const char * | szPassword, | ||
const void * | lpSeed, | ||
long | nSeedLen, | ||
long | nOptions | ||
) |
Generate an RSA key pair and save as two key files.
[Superseded by RSA_MakeKeysXtd.]
[in] | szPubKeyFile | name of public key file to be created. |
[in] | szEpkFile | name of encrypted private key file to be created. |
[in] | nBits | required key size in bits (minimum 96). |
[in] | nExpFermat | exponent e to be used. Select from:PKI_RSAEXP_EQ_3 for 3PKI_RSAEXP_EQ_5 for 5PKI_RSAEXP_EQ_17 for 17 (0x11)PKI_RSAEXP_EQ_257 for 257 (0x101)PKI_RSAEXP_EQ_65537 for 65537 (0x10001) (default) |
[in] | nTests | specifying the number of Rabin-Miller tests to be performed (recommended at least 50). |
[in] | nCount | specifying the iteration count to be used when encrypting the private key (default = 1; recommended at least 1000). |
[in] | szPassword | password to be used to encrypt the private key file. |
[in] | lpSeed | an (optional) user-specified seed to be used by the random number generator (specify "" or NULL to ignore). |
[in] | nSeedLen | length of the seed in bytes. |
[in] | nOptions | a flag to indicate the algorithm to be used to encrypt the private key file. Select from:PKI_PBE_SHA_3DES (0) for "pbeWithSHAAnd3-KeyTripleDES-CBC" (default)or PKI_PBE_PBES2 for "pkcs5PBES2" plus one of
and optionally add PKI_KEYGEN_INDICATE to indicate progress in a console window (see remarks below),plus one of PKI_KEY_FORMAT_PEM to save the key files in PEM form (default is binary BER-encoded format) or PKI_KEY_FORMAT_SSL to save the key files in PEM form with the public key as an OpenSSL-compatible subjectPublicKeyInfo file. |
RSAPublicKey
and RSAPrivateKey
respectively (defined in PKCS #1). The private key is then encrypted and encoded into a PKCS #8 EncryptedPrivateKeyInfo
type. Any existing files of the same names will be overwritten without warning. The key length must be greater than 96 bits. The value of the exponent is limited to the five values listed. The password and iteration count are used to encrypt the private key according to the specified PBE algorithm specified in nOptionFlags. The password should be a string of ASCII characters and must not contain any NUL characters (i.e. Chr
). The seed is optional and is used to supplement the seeding of the random number generator. The user may use the seed to provide some additional value ("user-supplied entropy") that is unique when the keys are being generated. See Random Number Generator and Seeds for more information.The default format for the files is binary DER-encoded format. Use either the PKI_KEY_FORMAT_PEM
or the PKI_KEY_FORMAT_SSL
flag to save in base64 "PEM" format. Files saved with the PKI_KEY_FORMAT_SSL
flag should be compatible with OpenSSL. For more details on the formats, see RSA_SavePublicKey()
and RSA_SaveEncPrivateKey()
.
Generating RSA key pairs can take some time. On a 1GHz P3 test machine, the following times were typical:
Key size | Time |
---|---|
512 | < 1 second |
1024 | 5 seconds |
2048 | 1 minute |
4096 | 6 minutes |
8192 | 1 hour |
Some programs like Office Access will get bored waiting for the longer processes to finish and may hang. Setting the PKI_KEYGEN_INDICATE
flag will show progress in a separate console window (actually two, one for p and one for q). Having a console window show progress will keep the parent application happy. A dot "." indicates a new candidate is being tested, and an asterisk "*" indicates that a Rabin-Miller test has been carried out (that is the expensive part of the process). The program will close these console windows down automatically. Do not use the PKI_KEYGEN_INDICATE
option in a multi-threaded environment. For console-based programs, this option just shows the progress in the standard output.
Caution: pressing Ctrl-C or Ctrl-Break in the console window will kill your entire process altogether; that is, abort your whole application, which may not be what you want.
There is a very, very small possibility that the generator may fail to find a suitable prime number candidate within the number of iterations it carries out. If this happens (we've never seen it, but it could in theory), the function will return a KEYGEN_FAILED_ERROR
error code 24. This in itself does not indicate a systemic problem with the Toolkit, just an incredibly unlucky event. Let us know if it happens more than once.
long RSA_MakeKeysXtd | ( | const char * | szPubKeyFile, |
const char * | szPriKeyFile, | ||
const char * | szPassword, | ||
long | nBits, | ||
long | nExpFermat, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Generate an RSA key pair and save as two key files.
[in] | szPubKeyFile | Output filename for public key. |
[in] | szPriKeyFile | Output filename for (encrypted) private key. |
[in] | szPassword | Password for encrypted private key (required). |
[in] | nBits | Required key modulus size in bits (minimum 96). |
[in] | nExpFermat | exponent e to be used. Select from:PKI_RSAEXP_EQ_3 for 3PKI_RSAEXP_EQ_5 for 5PKI_RSAEXP_EQ_17 for 17 (0x11)PKI_RSAEXP_EQ_257 for 257 (0x101)PKI_RSAEXP_EQ_65537 for 65537 (0x10001) (default) |
[in] | szParams | Optional parameters. Set as the empty string "" for defaults. Otherwise include a set of attribute-value pairs separated by a semi-colon ";" to set options from the following
{hmacWithSHA1|hmacWithSHA224|hmacWithSHA256|hmacWithSHA384|hmacWithSHA512} . |
[in] | nOptions | a flag to indicate the password-based encryption scheme to be used to encrypt the private key file. Select from:PKI_PBE_SHA_3DES (0) for "pbeWithSHAAnd3-KeyTripleDES-CBC" from PKCS12 (default)PKI_PBE_PBKDF2_DESEDE3 for PBKDF2 using des-EDE3-CBC PKI_PBE_PBKDF2_AES128 for PBKDF2 using aes128-CBC PKI_PBE_PBKDF2_AES192 for PBKDF2 using aes192-CBC PKI_PBE_PBKDF2_AES256 for PBKDF2 using aes256-CBC (there are more options - see security options for encrypted private keys) and optionally add PKI_KEYGEN_INDICATE to indicate progress in a console window (see remarks below),plus one of PKI_KEY_FORMAT_PEM to save the key files in PEM form (default is binary DER-encoded format) or PKI_KEY_FORMAT_SSL to save the key files in PEM form with the public key as an OpenSSL-compatible subjectPublicKeyInfo file. |
Setting the PKI_KEYGEN_INDICATE
flag will show progress in a separate console window (actually two, one for p and one for q). Having a console window show progress will keep a parent application (like MS Access) happy and prevent it hanging due to boredom. The program will close these console windows down automatically (do not use Ctrl-C or Ctrl-Break: it will kill your entire process altogether!). Do not use the PKI_KEYGEN_INDICATE
option in a multi-threaded environment. For console-based programs, this option just shows the progress in the standard output.
long RSA_PublicKeyFromPrivate | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyString, | ||
long | nOptions | ||
) |
Converts an internal RSA private key string into an internal public key string.
[out] | szOutput | to receive public key data in encoded "internal" format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyString | containing a private key in "internal" format. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
Use this function if you need a public key string but only have the corresponding private key file. The format used to store RSA private keys contains both the public and private components (that is, n and e are present in both) so we can obtain the public key from its corresponding private key.
Note that internal key strings are only valid for the current session.
long RSA_RawPrivate | ( | unsigned char * | lpData, |
long | nDataLen, | ||
const char * | szPrivateKey, | ||
long | nOptions | ||
) |
Transforms (that is, encrypts or decrypts) raw data using an RSA private key.
[in,out] | lpData | array containing the data to be transformed. |
[in] | nDataLen | specifying the number of bytes of data. |
[in] | szPrivateKey | containing the RSA private key string. |
[in] | nOptions | option flags. Set to zero. |
RSA_KeyBytes()
to find out this). The output is written over the input. The RSA private key must be provided in the internal key string format. long RSA_RawPublic | ( | unsigned char * | lpData, |
long | nDataLen, | ||
const char * | szPublicKey, | ||
long | nOptions | ||
) |
Transforms (that is, encrypts or decrypts) raw data using an RSA public key.
[in,out] | lpData | array containing the data to be transformed. |
[in] | nDataLen | specifying the number of bytes of data. |
[in] | szPublicKey | containing the RSA public key string. |
[in] | nOptions | option flags. Set to zero. |
RSA_KeyBytes()
to find out this). The output is written over the input. The RSA public key must be provided in the internal key string format. long RSA_ReadAnyPrivateKey | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyFileOrString, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Reads from a file or string containing a private key into an "internal" private key string.
[out] | szOutput | to receive encoded private key data in "internal" format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyFileOrString | specifying either the name of file containing the private key or a string containing the key in PEM format or XML format. |
[in] | szPassword | containing the password, if the key is encrypted, or "" if not encrypted. |
[in] | nOptions | not used in this release. Specify zero. |
This function will attempt to read the private key from "any" supported format. The output will be an ephemeral "internal" key string suitable for the current session only.
Supported formats are:
RSAKeyPair
element This supersedes the following functions:
RSA_ReadEncPrivateKey
RSA_ReadPrivateKeyInfo
RSA_ReadPrivateKeyFromPFX
long RSA_ReadAnyPublicKey | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyFileOrString, | ||
long | nOptions | ||
) |
Reads from a file or string containing a public key into an "internal" public key string.
[out] | szOutput | to receive encoded public key data in "internal" format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyFileOrString | specifying the name of file containing the key or a string containing the key in PEM format or XML format. |
[in] | nOptions | not used in this release. Specify zero. |
This function will attempt to read the public key from "any" supported format. The output will be an ephemeral "internal" key string suitable for the current session only.
Supported formats are:
RSAKeyValue
or RSAKeyPair
element To read in a public key from a PFX/p12 file, use RSA_ReadAnyPrivateKey
then RSA_PublicKeyFromPrivate
.
This supersedes the following functions:
RSA_ReadPublicKey
RSA_GetPublicKeyFromCert
long RSA_ReadEncPrivateKey | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szEpkFile, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Reads from an encrypted PKCS#8 private key info file into an "internal" private key string.
[Superseded by RSA_ReadAnyPrivateKey.]
[out] | szOutput | to receive encoded private key data in "internal" format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szEpkFile | specifying the filename of a PKCS-8 encrypted private key info file (or a string containing the key in PEM format). |
[in] | szPassword | containing the password |
[in] | nOptions | not used in this release. Specify zero. |
EncryptedPrivateKeyInfo
data using the rsaEncryption
algorithm is supported. The file must be either in binary BER-encoded format or PEM format. long RSA_ReadPrivateKeyFromPFX | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szPfxFile, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Reads a private key directly from an encrypted PFX/PKCS-12 file into an "internal" private key string.
[Superseded by RSA_ReadAnyPrivateKey.]
[out] | szOutput | to receive private key data in "internal" encoded format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szPfxFile | containing the PFX filename (or a string containing the PFX data in PEM format) |
[in] | szPassword | containing the password. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
pkcs8ShroudedKeyBag
object it finds and can decrypt in the PFX file. The result is a string in "internal" key string format valid only for the current session. Call the function with an empty or NULL szOutput string or zero nOutChars parameter to find out the required length of the output string. C/C++ users should add one to this value when allocating memory.If you need the public key instead from a PFX file, then use this function followed by RSA_PublicKeyFromPrivate()
.
If you just want to extract the encrypted private key and save directly as a pkcs-8 file, then use the RSA_GetPrivateKeyFromPFX()
function.
long RSA_ReadPrivateKeyInfo | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyFile, | ||
long | nOptions | ||
) |
Reads from an (unencrypted) PKCS-8 private key info file into an "internal" private key string.
[Superseded by RSA_ReadAnyPrivateKey.]
[out] | szOutput | to receive private key data in "internal" encoded format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyFile | specifying the filename of a PrivateKeyInfo file (or a string containing the key in PEM format). |
[in] | nOptions | option flags: not used in this release. Specify zero. |
PrivateKeyInfo
files specifying the rsaEncryption
algorithm are supported together with OpenSSL-compatible RSA PRIVATE KEY
files. Files may be in either binary BER/DER-encoded format or PEM format. Call the function with an empty or NULL szOutput string or zero nOutChars parameter to find out the required length of the output string. C/C++ users should add one to this value when allocating memory. long RSA_ReadPublicKey | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szPubKeyFile, | ||
long | nOptions | ||
) |
Reads from an RSA public key file into an "internal" public key string.
[Superseded by RSA_ReadAnyPublicKey.]
[out] | szOutput | to receive public key data in encoded "internal" format. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szPubKeyFile | specifying the filename of a public key file (or a string containing the key in PEM format). |
[in] | nOptions | option flags: not used in this release. Specify zero. |
RSAPublicKey
and OpenSSL SubjectPublicKeyInfo
formats are supported. The file can be in binary BER-encoded format or PEM format, or be passed as a string containing the data in PEM format. Call the function with an empty or NULL szOutput string or zero nOutChars parameter to find out the required length of the output string. C/C++ users should add one to this value when allocating memory. long RSA_SaveEncKey | ( | const char * | szFileOut, |
const char * | szIntKeyString, | ||
const char * | szPassword, | ||
const char * | szParams, | ||
long | nOptions | ||
) |
Save an internal RSA key string to an encrypted key file.
[in] | szFileOut | Name of output file to be created. |
[in] | szIntKeyString | The private RSA key as an internal key string. |
[in] | szPassword | Password for encrypted private key (required). |
[in] | szParams | Optional parameters. Set as the empty string "" for defaults. Otherwise include a set of attribute-value pairs separated by a semi-colon ";" to set options from the following
{hmacWithSHA1|hmacWithSHA224|hmacWithSHA256|hmacWithSHA384|hmacWithSHA512} . |
[in] | nOptions | option flags: to specify the PBE algorithm. Select one of:PKI_PBE_SHA_3DES (0) to use pbeWithSHAAnd3-KeyTripleDES-CBC from PKCS12 (default)PKI_PBE_PBKDF2_DESEDE3 for PBKDF2 using des-EDE3-CBC PKI_PBE_PBKDF2_AES128 for PBKDF2 using aes128-CBC PKI_PBE_PBKDF2_AES192 for PBKDF2 using aes192-CBC PKI_PBE_PBKDF2_AES256 for PBKDF2 using aes256-CBC (there are more options - see security options for encrypted private keys) and optionally add PKI_KEY_FORMAT_PEM to export an ENCRYPTED PRIVATE KEY PEM-format file (default is binary BER-encoded format). |
long RSA_SaveEncPrivateKey | ( | const char * | szFileOut, |
const char * | szKeyString, | ||
long | nCount, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Saves a private key string to a PKCS-8 encrypted private key info file.
[in] | szFileOut | specifying the filename of the output file to be created. |
[in] | szKeyString | containing the private key string |
[in] | nCount | specifying the number of iterations to carry out |
[in] | szPassword | containing the password |
[in] | nOptions | option flags: to specify the PBE algorithm. Select one of:PKI_PBE_SHA_3DES (0) to use pbeWithSHAAnd3-KeyTripleDES-CBC (default)PKI_PBE_PBKDF2_DESEDE3 for PBKDF2 using des-EDE3-CBC PKI_PBE_PBKDF2_AES128 for PBKDF2 using aes128-CBC PKI_PBE_PBKDF2_AES192 for PBKDF2 using aes192-CBC PKI_PBE_PBKDF2_AES256 for PBKDF2 using aes256-CBC (there are more options - see security options for encrypted private keys) and optionally add PKI_KEY_FORMAT_PEM to export an ENCRYPTED PRIVATE KEY PEM-format file (default is binary BER-encoded format). |
PKI_KEY_FORMAT_PEM
option is added, the file be will in PEM format. The PEM encrypted private key format uses the header and footer lines:-----BEGIN ENCRYPTED PRIVATE KEY----- -----END ENCRYPTED PRIVATE KEY-----
long RSA_SavePrivateKeyInfo | ( | const char * | szFileOut, |
const char * | szKeyString, | ||
long | nOptions | ||
) |
Saves a private key string to an (unencrypted) PKCS-8 private key info file.
[in] | szFileOut | specifying the filename of the output file to be created. |
[in] | szKeyString | containing the private key string |
[in] | nOptions | Option flags. Select one of:PKI_DEFAULT (0) to export a binary BER-encoded file (default)PKI_KEY_FORMAT_PEM to export a PEM-like PRIVATE KEY filePKI_KEY_FORMAT_SSL to export an OpenSSL-compatible RSA PRIVATE KEY PEM fileand optionally add |
Any existing file of the specified name will be overwritten without warning. Saves by default as a binary BER-encoded file compatible with the PKCS-8 PrivateKeyInfo format. The PEM key format saved with the PKI_KEY_FORMAT_PEM
option uses the header and footer lines:
-----BEGIN PRIVATE KEY----- -----END PRIVATE KEY-----
The OpenSSL-compatible PEM key format saved with the PKI_KEY_FORMAT_SSL
option uses the header and footer lines:
-----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----
and is compatible with the PKCS-1 RSAPrivateKey format.
long RSA_SavePublicKey | ( | const char * | szFileOut, |
const char * | szKeyString, | ||
long | nOptions | ||
) |
Saves a public key string to PKCS-1 public key file.
[in] | szFileOut | specifying the filename of the output file to be created. |
[in] | szKeyString | containing the public key string (or a private key string) |
[in] | nOptions | Option flags. Select one of:PKI_DEFAULT (0) to export a binary DER/BER-encoded file (default)PKI_KEY_FORMAT_PEM to export a PEM-like "RSA PUBLIC KEY" filePKI_KEY_FORMAT_SSL to export an OpenSSL-compatible "PUBLIC KEY" PEM file |
PKI_KEY_FORMAT_PEM
option is the same data in PEM format with header and footer lines:-----BEGIN RSA PUBLIC KEY----- -----END RSA PUBLIC KEY-----
The file saved with the PKI_KEY_FORMAT_SSL
option is compatible with the format used by OpenSSL. The data is saved as X.509 SubjectPublicKeyInfo format encoded with header and footer lines:
-----BEGIN PUBLIC KEY----- -----END PUBLIC KEY-----
The OpenSSL format key is saved with "Unix" line endings and a line length of strictly 64 characters.
You can use this function to extract a public key from a private key. Just pass the internal private key string instead of the public key string.
long RSA_ToXMLString | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyString, | ||
long | nOptions | ||
) |
Creates an XML string representation of an RSA internal key string.
[out] | szOutput | to receive XML data. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyString | containing the RSA public or private key in internal format |
[in] | nOptions | option flags: Select and combine:PKI_DEFAULT (0) to output in appropriate W3C standard format (RSAKeyValue for public key and RSAKeyPair for private key)PKI_XML_RSAKEYVALUE to force private key output as .NET-compatible RSAKeyValue format (instead of W3C RSAKeyPair )PKI_XML_EXCLPRIVATE to exclude the private key (use to get a public key RSAKeyValue from a private key)PKI_XML_HEXBINARY to output with data in non-conforming hexBinary format |
Caution: the private key is saved in unencrypted form. Do not use for a production key.
Both public and private key data can be output. The key must have been read first into an internal key string using one of the other RSA key input functions in this toolkit.
If the internal key is a public key, or if the PKI_XML_EXCLPRIVATE
option is used with a private key, the output will always be a RSAKeyValue
element containing just <Modulus>
and <Exponent>
elements as per [XMLDSIG].
If the internal key is a private key and the PKI_XML_EXCLPRIVATE
option is not used, the default output will be a a XKMS-conforming RSAKeyPair
element with the private key parameters included. Including the PKI_XML_RSAKEYVALUE
option will force a .NET-compatible RSAKeyValue
element instead. The only difference between RSAKeyPair
and RSAKeyValue
is in the name of the outer XML element. The default behaviour is to comply with the W3C standards [XKMS] and [XMLDSIG]. Users who wish to export a private key to use in the .NET world will probably want to use the PKI_XML_RSAKEYVALUE
option.
The PKI_XML_HEXBINARY
option will output the binary data in hexBinary
encoding format instead of base64. This latter format is not in conformance with any W3C standard, but is provided to allow users to see the data in more readable hex format. Such a format can be read by
this toolkit's RSA_FromXMLString()
function, but don't try using it anywhere else.
long RSA_ToXMLStringEx | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szKeyString, | ||
const char * | szPrefix, | ||
long | nOptions | ||
) |
Creates an XML string representation of an RSA internal key string with option to add a namespace prefix.
[out] | szOutput | to receive XML data. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szKeyString | containing the RSA public or private key in internal format |
[in] | szPrefix | the namespace prefix to be added to all elements |
[in] | nOptions | option flags: Select and combine:PKI_DEFAULT (0) to output in appropriate W3C standard format (RSAKeyValue for public key and RSAKeyPair for private key)PKI_XML_RSAKEYVALUE to force private key output as .NET-compatible RSAKeyValue format (instead of W3C RSAKeyPair )PKI_XML_EXCLPRIVATE to exclude the private key (use to get a public key RSAKeyValue from a private key)PKI_XML_HEXBINARY to output with data in non-conforming hexBinary format |
Use this extended function to add a namespace prefix to all elements in the XML output; for example, <ds:RSAKeyValue>
. Note that it's up to the user to map the prefix to a URI somewhere in the final XML document (for reference, the correct form is xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
).
See also the remarks for RSA_ToXMLString.
long SIG_SignData | ( | char * | szOutput, |
long | nOutChars, | ||
const unsigned char * | lpData, | ||
long | nDataLen, | ||
const char * | szKeyFile, | ||
const char * | szPassword, | ||
const char * | szAlgName, | ||
long | nOptions | ||
) |
Compute a signature value over data in a byte array.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | lpData | byte array containing the input data to be signed. |
[in] | nDataLen | specifying the length of the input data in bytes. |
[in] | szKeyFile | specifying the name of the private key file (or a string containing the key in PEM format, or a valid internal private key string). |
[in] | szPassword | containing the password for the private key, or "" if not required. |
[in] | szAlgName | specifying the signature algorithm (case insensitive):"sha1WithRSAEncryption" (default - CAUTION)"sha224WithRSAEncryption" "sha256WithRSAEncryption" [minimum recommended]"sha384WithRSAEncryption" "sha512WithRSAEncryption" "md5WithRSAEncryption" [for legacy applications - not recommended for new implementations]"ecdsaWithSHA1" "ecdsaWithSHA224" "ecdsaWithSHA256" "ecdsaWithSHA384" "ecdsaWithSHA512" "RSA-PSS-SHA1" "RSA-PSS-SHA224" "RSA-PSS-SHA256" "RSA-PSS-SHA384" "RSA-PSS-SHA512" "Ed25519" [New in v20.0] (see Remarks)"Ed448" [New in v22.0] (see Remarks)or "" to use the signature algorithm flag in nOptions, see Specifying the signature algorithm in a SIG_ function. |
[in] | nOptions | Zero (0) for defaults. Add the bitflag:
To change the format of the output (default base64 encoded), add one of:
Options for ECDSA signatures only:
Options for RSA-PSS signatures only: [New in v12.0] (see RSA signature and encryption schemes) Add one of the following to specify the salt length:
|
Computes the signature value over the input data (or its digest value) using the private key provided. The default output is a continuous string of base64 characters suitable to include in the <SignatureValue>
node of an XML-DSIG document. Alternative output encodings (base64url and hex) can be specified using the PKI_ENCODE_
options.
The PKI_SIG_USEDIGEST
option cannot be used with Ed25519 or Ed448. The data to be signed must be passed in toto to the signature function. All options except the PKI_ENCODE_
options are ignored for the Ed25519 and Ed448 algorithms.
long SIG_SignFile | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szDataFile, | ||
const char * | szKeyFile, | ||
const char * | szPassword, | ||
const char * | szAlgName, | ||
long | nOptions | ||
) |
Compute a signature value over data in a file.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szDataFile | specifying the file containing the input data to be signed. |
[in] | szKeyFile | specifying the name of the private key file (or a string containing the key in PEM format, or a valid internal private key string). |
[in] | szPassword | containing the password for the private key, or "" if not required. |
[in] | szAlgName | specifying the signature algorithm (case insensitive):"sha1WithRSAEncryption" (default - CAUTION)"sha224WithRSAEncryption" "sha256WithRSAEncryption" [minimum recommended]"sha384WithRSAEncryption" "sha512WithRSAEncryption" "md5WithRSAEncryption" [for legacy applications - not recommended for new implementations]"ecdsaWithSHA1" "ecdsaWithSHA224" "ecdsaWithSHA256" "ecdsaWithSHA384" "ecdsaWithSHA512" "RSA-PSS-SHA1" "RSA-PSS-SHA224" "RSA-PSS-SHA256" "RSA-PSS-SHA384" "RSA-PSS-SHA512" (Note that Ed25519 and Ed448 are not available with this function - see Remarks)or "" to use the signature algorithm flag in nOptions, see Specifying the signature algorithm in a SIG_ function. |
[in] | nOptions | Zero (0) for defaults. To change the format of the output (default base64 encoded), add one of:
Options for ECDSA signatures only:
Options for RSA-PSS signatures only: [New in v12.0] (see RSA signature and encryption schemes) Add one of the following to specify the salt length:
|
This function is identical to SIG_SignData
except the data to be signed is in a file.
The Ed25519 and Ed448 signature algorithms are not available with this function. To sign using Ed25519 or Ed448, read in the file to a byte array and use SIG_SignData.
long SIG_VerifyData | ( | const char * | szSignature, |
const unsigned char * | lpData, | ||
long | nDataLen, | ||
const char * | szCertOrKeyFile, | ||
const char * | szAlgName, | ||
long | nOptions | ||
) |
Verify a signature value over data in a byte array.
[in] | szSignature | string containing the signature value encoded in base64. |
[in] | lpData | byte array containing the input data to be verified. |
[in] | nDataLen | specifying the length of the input data in bytes. |
[in] | szCertOrKeyFile | specifying the X.509 certificate or public key file (or a string containing the certificate or key in PEM format or base64 representation). |
[in] | szAlgName | specifying the signature algorithm (case insensitive):"sha1WithRSAEncryption" (default)"sha224WithRSAEncryption" "sha256WithRSAEncryption" "sha384WithRSAEncryption" "sha512WithRSAEncryption" "md5WithRSAEncryption" "ecdsaWithSHA1" "ecdsaWithSHA224" "ecdsaWithSHA256" "ecdsaWithSHA384" "ecdsaWithSHA512" "RSA-PSS-SHA1" "RSA-PSS-SHA224" "RSA-PSS-SHA256" "RSA-PSS-SHA384" "RSA-PSS-SHA512" "Ed25519" [New in v20.0] (see Remarks)"Ed448" [New in v22.0] (see Remarks)or "" to use the signature algorithm flag in nOptions, see Specifying the signature algorithm in a SIG_ function. |
[in] | nOptions | Zero (0) for defaults.PKI_SIG_USEDIGEST to pass the digest value of the data-to-be-verified as a byte array in the lpData parameter instead of the data itself.PKI_MGF_MGF1SHA1 (RSA-PSS only) to force the MGF hash function to be SHA-1 (default = same as signature hash algorithm). |
For RSA-PSS, the MGF hash algorithm is assumed to be the same as the signature hash algorithm (see RSA signature and encryption schemes). If the signature was created using mgf1SHA1
with a signature hash algorithm other than SHA-1, then you must add the option PKI_MGF_MGF1SHA1
. Other combinations of signature hash algorithm/MGF hash algorithm are not supported.
The PKI_SIG_USEDIGEST
option cannot be used with Ed25519 or Ed448. The data to be verified must be passed in toto to the verify function.
long SIG_VerifyFile | ( | const char * | szSignature, |
const char * | szDataFile, | ||
const char * | szCertOrKeyFile, | ||
const char * | szAlgName, | ||
long | nOptions | ||
) |
Verify a signature value over data in a file.
[in] | szSignature | string containing the signature value encoded in base64. |
[in] | szDataFile | specifying the file containing the input data to be verified. |
[in] | szCertOrKeyFile | specifying the X.509 certificate or public key file (or a string containing the certificate or key in PEM format or base64 representation). |
[in] | szAlgName | specifying the signature algorithm (case insensitive):"sha1WithRSAEncryption" (default)"sha224WithRSAEncryption" "sha256WithRSAEncryption" "sha384WithRSAEncryption" "sha512WithRSAEncryption" "md5WithRSAEncryption" [for legacy applications - not recommended for new implementations]"ecdsaWithSHA1" "ecdsaWithSHA224" "ecdsaWithSHA256" "ecdsaWithSHA384" "ecdsaWithSHA512" "RSA-PSS-SHA1" "RSA-PSS-SHA224" "RSA-PSS-SHA256" "RSA-PSS-SHA384" "RSA-PSS-SHA512" (Note that Ed25519 and Ed448 are not available with this function - see Remarks)or "" to use the signature algorithm flag in nOptions, see Specifying the signature algorithm in a SIG_ function. |
[in] | nOptions | Zero (0) for defaults.PKI_MGF_MGF1SHA1 (RSA-PSS only) to force the MGF hash function to be SHA-1 (default = same as signature hash algorithm). |
SIG_VerifyData
except the data to be verified is in a file.The Ed25519 and Ed448 signature algorithms are not available with this function. To verify using Ed25519 or Ed448, read in the file to a byte array and use SIG_VerifyData.
long SMIME_Extract | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
long | nOptions | ||
) |
Extract the body from an S/MIME entity.
[in] | szFileOut | string specifying the filename of the output file to be created. |
[in] | szFileIn | string specifying the filename of the input file. |
[in] | nOptions | Zero (0) for defaults.PKI_SMIME_ENCODE_BASE64 to encode the output in base64 encoding (default is binary). |
application/pkcs7-mime
with base64 or binary transfer encoding. In practice, it will extract the body from almost any type of S/MIME (or MIME) file, except one with quoted-printable transfer encoding. long SMIME_Query | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szFileIn, | ||
const char * | szQuery, | ||
long | nOptions | ||
) |
Query an S/MIME entity.
[out] | szOutput | string of sufficient length to receive the output. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szFileIn | string specifying the filename of the input file. |
[in] | szQuery | specifying the query (see Remarks below). |
[in] | nOptions | option flags: not used in this release. Specify zero. |
Query String | Returns |
---|---|
content-type | Value of Content-Type, e.g. "application/pkcs7-mime" |
smime-type | Value of smime-type parameter of Content-Type, e.g. "enveloped-data" |
encoding | Value of Content-Transfer-Encoding, e.g. "base64" |
name | Value of name parameter of Content-Type, e.g. "smime.p7m" |
filename | Value of filename parameter of Content-Disposition, e.g. "smime.p7m" |
If no value is found corresponding to the query then the zero-length empty string ""
is output.
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
long SMIME_Wrap | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const char * | szFeatures, | ||
long | nOptions | ||
) |
Wrap a CMS object in an S/MIME entity.
[in] | szFileOut | string specifying the filename of the output file to be created. |
[in] | szFileIn | string specifying the filename of the input file. |
[in] | szFeatures | string to specify special features. For future use. Leave empty "" or NULL for defaults. |
[in] | nOptions | Zero (0) for defaults.PKI_SMIME_ENCODE_BINARY to encode the body in binary encoding (default is base64).PKI_SMIME_ADDX to add an "x-" to the content subtype. |
application/pkcs7-mime
from a binary CMS object. It works in file-to-file mode only. The input file is expected to be a binary CMS object of type enveloped-data, signed-data or compressed-data; otherwise it is an error. The type of input file is detected automatically. The output is a text file with the correct S/MIME headers according to [SMIME-MSG]. By default the body is encoded in base64. Use the PKI_SMIME_ENCODE_BINARY
option to encode the body in "binary" instead.Use the PKI_SMIME_ADDX
option to change the Content-Type to application/x-pkcs7-mime
for compatibility with legacy applications.
S/MIME signed messages with the multipart/signed
format are currently not supported.
long TDEA_B64Mode | ( | char * | szOutput, |
const char * | szInput, | ||
const char * | szKey, | ||
long | fEncrypt, | ||
const char * | szMode, | ||
const char * | szIV | ||
) |
Encrypts or decrypts data encoded in base64 using a specified mode.
The key and initialization vector are required in base64.
[out] | szOutput | of sufficient length to receive the output. |
[in] | szInput | containing the input data in base64. |
[in] | szKey | containing the key in base64 format. |
[in] | fEncrypt | direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt. |
[in] | szMode | specifying the confidentiality mode:"ECB" for Electronic Codebook mode,"CBC" for Cipher Block Chaining mode,"CFB" for 64-bit Cipher Feedback mode,"OFB" for Output Feedback mode, or"CTR" for Counter mode. |
[in] | szIV | containing the initialization vector (IV), if required, in base64 format. |
ECB
, in which case szIV is ignored (use ""
). Valid base64 characters are [A-Za-z0-9+/] with '=' used as a padding character. The output string szOutput must be set up with at least the same number of characters as the input string before calling. The variables szOutput and szInput should be different. long TDEA_BytesMode | ( | unsigned char * | lpOutput, |
const unsigned char * | lpData, | ||
long | nDataLen, | ||
const unsigned char * | lpKey, | ||
long | fEncrypt, | ||
const char * | szMode, | ||
const unsigned char * | lpIV | ||
) |
Encrypts or decrypts an array of Bytes in one step using a specified mode.
[out] | lpOutput | array of sufficient length to receive the output. |
[in] | lpData | array containing the input data. |
[in] | nDataLen | equal to length of the input data in bytes. |
[in] | lpKey | array containing the key. |
[in] | fEncrypt | direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt. |
[in] | szMode | specifying the confidentiality mode:"ECB" for Electronic Codebook mode,"CBC" for Cipher Block Chaining mode,"CFB" for 64-bit Cipher Feedback mode,"OFB" for Output Feedback mode, or"CTR" for Counter mode. |
[in] | lpIV | array containing the initialization vector (IV), or zero (0) for ECB mode. |
long TDEA_File | ( | const char * | szFileOut, |
const char * | szFileIn, | ||
const unsigned char * | lpKey, | ||
long | fEncrypt, | ||
const char * | szMode, | ||
const unsigned char * | lpIV | ||
) |
Encrypts or decrypts a file using a specified mode.
The key and initialization vector are passed as arrays of bytes. PKCS-5/7 padding is used.
[in] | szFileOut | with the full path name of the output file to be created. |
[in] | szFileIn | with the full path name of the input file to be processed. |
[in] | lpKey | array containing the key. |
[in] | fEncrypt | direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt. |
[in] | szMode | specifying the confidentiality mode:"ECB" for Electronic Codebook mode,"CBC" for Cipher Block Chaining mode,"CFB" for 64-bit Cipher Feedback mode,"OFB" for Output Feedback mode, or"CTR" for Counter mode. |
[in] | lpIV | array containing the initialization vector (IV), or zero (0) for ECB mode. |
0
).The output file szFileOut will be overwritten without warning. If there is an error, the output file will not exist. The input and output files must not be the same.
In ECB and CBC modes, a padding string will be added or assumed according to the method outlined in Section 6.3 of [CMS], which is the same as the padding method in [PKCS7] section 10.3 and [PKCS5] section 6.1.1 and [RFC1423] para 1.1.
long TDEA_HexMode | ( | char * | szOutput, |
const char * | szInput, | ||
const char * | szKey, | ||
long | fEncrypt, | ||
const char * | szMode, | ||
const char * | szIV | ||
) |
Encrypts or decrypts data represented as a hexadecimal string using a specified mode.
The key and initialization vector are represented as a hexadecimal string.
[out] | szOutput | of sufficient length to receive the output. |
[in] | szInput | containing the input data in hex format. |
[in] | szKey | containing the key in hex format. |
[in] | fEncrypt | direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt. |
[in] | szMode | specifying the confidentiality mode:"ECB" for Electronic Codebook mode,"CBC" for Cipher Block Chaining mode,"CFB" for 64-bit Cipher Feedback mode,"OFB" for Output Feedback mode, or"CTR" for Counter mode. |
[in] | szIV | containing the initialization vector (IV), if required, in hex format. |
ECB
, in which case szIV is ignored (use ""
). Valid hexadecimal characters are [0-9A-Fa-f]. The output string szOutput must be set up with the same number of characters as the input string before calling. The variables szOutput and szInput should be different. long WIPE_Data | ( | void * | lpData, |
long | nDataLen | ||
) |
Zeroise data in memory.
[in,out] | lpData | array to be cleared. |
[in] | nDataLen | number of bytes in array to be cleared. |
long WIPE_File | ( | const char * | szFileName, |
long | nOptions | ||
) |
Wipe and delete a file using secure 7-pass DOD standards.
[in] | szFileName | specifying the file to be deleted. |
[in] | nOptions | Option flags [New in v12.0]. Select one of:PKI_WIPEFILE_DOD7 (0) to use DOD 7-pass (default)PKI_WIPEFILE_SIMPLE to overwrite with single pass of zero bytes (quicker but less secure). |
long X509_CertExpiresOn | ( | const char * | szCertFile, |
char * | szOutput, | ||
long | nOutChars, | ||
long | nOptions | ||
) |
Returns the date and time an X.509 certificate expires.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
[out] | szOutput | to receive the time-date string. |
[in] | nOutChars | specifying the maximum length of the time-date string. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
long X509_CertIssuedOn | ( | const char * | szCertFile, |
char * | szOutput, | ||
long | nOutChars, | ||
long | nOptions | ||
) |
Returns the date and time an X.509 certificate was issued.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
[out] | szOutput | to receive the time-date string. |
[in] | nOutChars | specifying the maximum length of the time-date string. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
long X509_CertIssuerName | ( | const char * | szCertFile, |
char * | szOutput, | ||
long | nOutChars, | ||
const char * | szDelim, | ||
long | nOptions | ||
) |
Extracts issuer's distinguished name from X.509 certificate.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
[out] | szOutput | to receive the name string. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szDelim | specifying the character to use as a delimiter (default ";"). |
[in] | nOptions | Option flags. Select one of:PKI_DEFAULT (0) (default)PKI_X509_LDAP to output the LDAP string representation as per RFC 4514PKI_X509_LATIN1 to try and convert Unicode/UTF-8/T.61 attribute strings to Latin-1 (8-bit ASCII) |
X509_CertSubjectName()
. long X509_CertIsValidNow | ( | const char * | szCertFile, |
long | nOptions | ||
) |
Verifies that an X.509 certificate is currently valid.
[in] | szCertFile | with the filename of the certificate (or base64 representation). |
[in] | nOptions | option flags: not used in this release. Specify zero. |
[Changed in v12.0] If the certificate is otherwise of correct format but has expired or is not yet valid, this function returns EXPIRED_ERROR
(16). Previous versions would return -1.
long X509_CertRequest | ( | const char * | szNewReqFile, |
const char * | szPriKeyFile, | ||
const char * | szDistName, | ||
const char * | szExtensions, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Creates a PKCS #10 certificate signing request (CSR) using the subject's private key file.
[in] | szNewReqFile | Name of new certificate request file to be created. |
[in] | szPriKeyFile | Name of subject's private key file (encrypted or unencrypted) or a PEM string containing the key. |
[in] | szDistName | Distinguished name string. See Specifying Distinguished Names for more details. |
[in] | szExtensions | (optional) Extensions: a list of attribute-value pairs separated by semicolons (;) to be added to an extensionRequest element. See X.509 Extensions Parameter. [New in v10.0]. |
[in] | szPassword | Password for subject's encrypted private key file. Specify the empty string "" if key not encrypted [New in v12.0]. |
[in] | nOptions | Option flags. Choose one signature algorithm from:PKI_SIG_SHA1RSA (0) to use sha1WithRSAEncryption (default - CAUTION)PKI_SIG_SHA224RSA to use sha224WithRSAEncryption PKI_SIG_SHA256RSA to use sha256WithRSAEncryption [minimum recommended]PKI_SIG_SHA384RSA to use sha384WithRSAEncryption PKI_SIG_SHA512RSA to use sha512WithRSAEncryption PKI_SIG_MD5RSA to use md5WithRSAEncryption [legacy, not recommended]PKI_SIG_MD2RSA to use md2WithRSAEncryption [legacy, definitely not recommended]PKI_SIG_RSA_PSS_SHA1 to use RSA-PSS-SHA1 PKI_SIG_RSA_PSS_SHA224 to use RSA-PSS-SHA224 PKI_SIG_RSA_PSS_SHA256 to use RSA-PSS-SHA256 PKI_SIG_RSA_PSS_SHA384 to use RSA-PSS-SHA384 PKI_SIG_RSA_PSS_SHA512 to use RSA-PSS-SHA512 PKI_SIG_ECDSA_SHA1 to use ecdsaWithSHA1 PKI_SIG_ECDSA_SHA224 to use ecdsaWithSHA224 PKI_SIG_ECDSA_SHA256 to use ecdsaWithSHA256 PKI_SIG_ECDSA_SHA384 to use ecdsaWithSHA384 PKI_SIG_ECDSA_SHA512 to use ecdsaWithSHA512 PKI_SIG_ED25519 to use Ed25519 [New in v20.0]PKI_SIG_ED448 to use Ed448 [New in v22.0]And add any combination of these:- PKI_X509_FORMAT_BIN to create a BER-encoded binary file (default = base64 PEM format)PKI_X509_REQ_KLUDGE to create a request with the "kludge" that omits the strictly mandatory attributes completely (default = include attributes with zero-length field)PKI_X509_UTF8 to encode the DN as UTF8String (default = PrintableString)Specialist options:- PKI_PSS_SALTLEN_ZERO to use a zero-length salt in an RSA-PSS signature.PKI_SIG_DETERMINISTIC to use the deterministic digital signature generation procedure of [RFC6979] for an ECDSA signature. |
long X509_CertSerialNumber | ( | const char * | szCertFile, |
char * | szOutput, | ||
long | nOutChars, | ||
long | nOptions | ||
) |
Returns the serial number of an X.509 certificate.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
[out] | szOutput | to receive the serial number. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default output in hexadecimal format PKI_X509_DECIMAL to output number in decimal format |
long X509_CertSubjectName | ( | const char * | szCertFile, |
char * | szOutput, | ||
long | nOutChars, | ||
const char * | szDelim, | ||
long | nOptions | ||
) |
Extracts subject's distinguished name from X.509 certificate.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
[out] | szOutput | to receive the name string. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | szDelim | specifying the character to use as a delimiter (default ";"). |
[in] | nOptions | Option flags. PKI_DEFAULT (0) (default)PKI_X509_LDAP to output the LDAP string representation as per RFC 4514PKI_X509_LATIN1 to try and convert Unicode/UTF-8/T.61 attribute strings to Latin-1 (8-bit ASCII) |
"C=AU;O=myorg;CN=Dave"
. Only the first character in szDelim is used. The default delimiter is a semi-colon (;) if an empty string or NULL is specified for szDelim. If the attribute key is not in our set of supported types, the OID will be expressed in dot notation, e.g. "2.5.4.4=My Surname"
.If an attribute value is encoded in a multi-byte-character string format (such as UTF8String or BMPString), the value will be expressed as a hexadecimal-encoded string [NB changed in v3.9]
preceded by the hash symbol ('#'
U+0023) and small letter x ('x'
U+0078), e.g.
"C=TW;<span class="withdrawn">O=E8 A1 8C E6 94 BF E9 99 A2</span>" (v3.8 and earlier) "C=TW;O=#xE8A18CE694BFE999A2" (v3.9 and later)
Use the PKI_X509_LATIN1
option to return the string encoded in Latin-1, if possible, so it will display properly on systems that cannot cope with UTF-8.
[New in v3.9] Use the PKI_X509_LDAP
option to obtain the distinguished name in LDAP string form instead. The examples above would be returned as "CN=Dave,O=myorg,C=AU"
and "O=\E8\A1\8C\E6\94\BF\E9\99\A2,C=TW"
, with commas as delimiters, the RDNs in reverse order, and non-printable-ASCII characters escaped in hexadecimal form "\xx" as per [RFC4514]. See LDAP string representation for more details. The szDelim parameter is ignored with the PKI_X509_LDAP
option.
The output using the PKI_X509_LDAP
option is suitable as content for an <X509SubjectName>
node in an XML-DSIG document.
long X509_CertThumb | ( | const char * | szCertFile, |
char * | szOutput, | ||
long | nOutChars, | ||
long | nOptions | ||
) |
Calculates the thumbprint (message digest hash) of an X.509 certificate.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
[out] | szOutput | to receive the message digest. |
[in] | nOutChars | specifying the maximum length of the digest string. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
The maximum length of the output string is PKI_MAX_HASH_CHARS
(C/C++ users add one). The default hash algorithm is SHA-1 and the result should match the SHA-1 thumbprint shown in the Windows Certificate Viewer.
long X509_CheckCertInCRL | ( | const char * | szCertFile, |
const char * | szCrlFile, | ||
const char * | szCRLIssuerCert, | ||
const char * | szDate, | ||
long | nOptions | ||
) |
Checks whether an X.509 certificate has been revoked in a Certificate Revocation List (CRL).
[in] | szCertFile | with name of X.509 certificate to be checked (or base64 representation). |
[in] | szCrlFile | with name of CRL file. |
[in] | szCRLIssuerCert | (optional) with name of X.509 certificate file for the entity that issued the CRL (or base64 representation). |
[in] | szDate | (optional) with date in ISO date format (e.g. 2009-12-31T12:59:59Z ) on or after you wish to check for revocation. Leave empty "" for any date. The time must be in GMT (UTC, Zulu time). |
[in] | nOptions | Option flags. Not used. Specify zero. |
SIGNATURE_ERROR
will result if the signature is invalid.You can directly verify the signature in the CRL file using the X509_VerifyCert() function.
[Changed in v12.0] If the certificate is otherwise of correct format but has been revoked, this function returns REVOCATION_ERROR
(42). Previous versions would return +1.
long X509_GetCertCountInP7Chain | ( | const char * | szP7cFile, |
long | nOptions | ||
) |
Return number of certificates in a PKCS-7 "certs-only" certificate chain file.
[in] | szP7cFile | filename of the PKCS-7 "certs-only" file, or a string containing its PEM textual representation. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
long X509_GetCertFromP7Chain | ( | const char * | szNewCertFile, |
const char * | szP7cFile, | ||
long | nIndex, | ||
long | nOptions | ||
) |
Extracts an X.509 certificate from a PKCS-7 "certs-only" certificate chain file (typically saved with extension .p7c or .p7b), saving the output directly as a new file.
[in] | szNewCertFile | filename of the output file to be created. |
[in] | szP7cFile | filename of the PKCS-7 "certs-only" file, or a string containing its PEM textual representation. |
[in] | nIndex | specifying which certificate (1,2,...) in the chain to extract, or 0 (deprecated) to return the count of certificates in the set. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
[New in v12.2] To find the number of certificates in the chain, use X509_GetCertCountInP7Chain. The old (deprecated) way to find the count of certificates was to set nIndex to zero.
long X509_GetCertFromPFX | ( | const char * | szNewCertFile, |
const char * | szPfxFile, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Extracts an X.509 certificate from a PKCS-12 PFX/.p12 file, saving the output directly as a new file.
[in] | szNewCertFile | specifying the filename of the output file to be created. |
[in] | szPfxFile | containing the PFX filename |
[in] | szPassword | containing password or "" if certificate is not encrypted |
[in] | nOptions | option flags: PKI_DEFAULT (0) to export a single DER-encoded X.509 certificate.PKI_PFX_P7CHAIN to output all certificates in a PKCS7 certificate chain file (.p7b or .p7c ). |
pkcs-12-certBag
found in the PFX file containing a x509Certificate
.Both unencrypted certificates and certificates encrypted with the weak 40-bit encryption used by "default" in Microsoft and OpenSSL PKCS-12 files are supported, but not any other encryption algorithm.
If no certificate can be found the function will return a negative NO_DATA_ERROR
error code.
The PKI_PFX_P7CHAIN
option will output all X.509 certificates found into a single PKCS#7 certificate chain file. The correct MIME-designated file extension for such a file is .p7c
, but for historical reasons Microsoft use .p7b
instead.
long X509_HashIssuerAndSN | ( | const char * | szCertFile, |
char * | szOutput, | ||
long | nOutChars, | ||
long | nOptions | ||
) |
Returns the message digest hash of the PKCS #7 issuerAndSerialNumber value of an X.509 certificate in hexadecimal format.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
[out] | szOutput | to receive the hash digest. |
[in] | nOutChars | specifying the maximum number of characters to be received. |
[in] | nOptions | Option flags. Select one of:PKI_HASH_SHA1 (0) to use the SHA-1 algorithm (default)PKI_HASH_SHA224 to use the SHA-224 algorithmPKI_HASH_SHA256 to use the SHA-256 algorithmPKI_HASH_SHA384 to use the SHA-384 algorithmPKI_HASH_SHA512 to use the SHA-512 algorithmPKI_HASH_MD5 to use the MD5 algorithm |
The certificate may be in binary BER format or base64 PEM format.
long X509_KeyUsageFlags | ( | const char * | szCertFile | ) |
Returns a bitfield containing the keyUsage flags for an X.509 certificate.
[in] | szCertFile | with the filename of the X.509 certificate (or base64 representation). |
digitalSignature 0x0001 nonRepudiation 0x0002 keyEncipherment 0x0004 dataEncipherment 0x0008 keyAgreement 0x0010 keyCertSign 0x0020 cRLSign 0x0040 encipherOnly 0x0080 decipherOnly 0x0100
These values are defined as PKI_X509_KEYUSAGE_DIGITALSIGNATURE
, etc.
long X509_MakeCert | ( | const char * | szNewCertFile, |
const char * | szIssuerCertFile, | ||
const char * | szSubjectPubKeyFile, | ||
const char * | szIssuerPriKeyFile, | ||
long | nCertNum, | ||
long | nYearsValid, | ||
const char * | szDistName, | ||
const char * | szExtensions, | ||
long | nKeyUsageFlags, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Creates an X.509 certificate using subject's public key and issuer's private key files.
[in] | szNewCertFile | Name of new certificate file to be created. | ||||||||||||||||||||
[in] | szIssuerCertFile | Name of issuer's X.509 certificate file (or its base64 representation or as a PEM string). | ||||||||||||||||||||
[in] | szSubjectPubKeyFile | Name of subject's public key file or a PEM string containing the key, or a valid internal key string. | ||||||||||||||||||||
[in] | szIssuerPriKeyFile | Name of issuer's private key file (encrypted or unencrypted) or a PEM string containing the key, or a valid internal key string. | ||||||||||||||||||||
[in] | nCertNum | Serial number for new certificate. Ignored if serialNumber is set in szExtensions. | ||||||||||||||||||||
[in] | nYearsValid | Number of years certificate is to be valid from current date and hour (can be changed with szExtensions). | ||||||||||||||||||||
[in] | szDistName | Distinguished name string. See Specifying Distinguished Names for more details. | ||||||||||||||||||||
[in] | szExtensions | Extensions: a list of attribute-value pairs separated by semicolons (;). See X.509 Extensions Parameter. Specify "" or NULL to ignore. | ||||||||||||||||||||
[in] | nKeyUsageFlags | Bit flags to set Key Usage extension:
| ||||||||||||||||||||
[in] | szPassword | Password for issuer's encrypted private key file. Specify the empty string "" if key not encrypted [New in v12.0]. | ||||||||||||||||||||
[in] | nOptions | Option flags. Choose one signature algorithm from:PKI_SIG_SHA1RSA (0) to use sha1WithRSAEncryption (default - CAUTION)PKI_SIG_SHA224RSA to use sha224WithRSAEncryption PKI_SIG_SHA256RSA to use sha256WithRSAEncryption [minimum recommended]PKI_SIG_SHA384RSA to use sha384WithRSAEncryption PKI_SIG_SHA512RSA to use sha512WithRSAEncryption PKI_SIG_MD5RSA to use md5WithRSAEncryption [legacy, not recommended]PKI_SIG_MD2RSA to use md2WithRSAEncryption [legacy, definitely not recommended]PKI_SIG_RSA_PSS_SHA1 to use RSA-PSS-SHA1 PKI_SIG_RSA_PSS_SHA224 to use RSA-PSS-SHA224 PKI_SIG_RSA_PSS_SHA256 to use RSA-PSS-SHA256 PKI_SIG_RSA_PSS_SHA384 to use RSA-PSS-SHA384 PKI_SIG_RSA_PSS_SHA512 to use RSA-PSS-SHA512 PKI_SIG_ECDSA_SHA1 to use ecdsaWithSHA1 PKI_SIG_ECDSA_SHA224 to use ecdsaWithSHA224 PKI_SIG_ECDSA_SHA256 to use ecdsaWithSHA256 PKI_SIG_ECDSA_SHA384 to use ecdsaWithSHA384 PKI_SIG_ECDSA_SHA512 to use ecdsaWithSHA512 PKI_SIG_ED25519 to use Ed25519 [New in v20.0]PKI_SIG_ED448 to use Ed448 [New in v22.0]And add any combination of these:- PKI_X509_VERSION1 to generate a Version 1 certificate, i.e. no extensions (default = Version 3).PKI_X509_CA_TRUE to set the basicConstraints subject type to be a CA (default = End Entity)PKI_X509_NO_BASIC to disable the basicConstraints extension (default = include)PKI_X509_UTF8 to encode the subject's DN fields as UTF8String (default = PrintableString)PKI_X509_FORMAT_PEM to save the certificate in PEM format (default = DER-encoded binary)PKI_X509_AUTHKEYID to add the issuer's KeyIdentifier, if present, as an AuthorityKeyIdentifer (default = do not add)Specialist options:- PKI_PSS_SALTLEN_ZERO to use a zero-length salt in an RSA-PSS signature.PKI_SIG_DETERMINISTIC to use the deterministic digital signature generation procedure of [RFC6979] for an ECDSA signature. |
PKI_X509_VERSION1
flag will, by definition, exclude any version 3 extensions.If the PKI_X509_UTF8
flag is set, each attribute of the subject's DN will be encoded as a UTF8String
. Otherwise the default encoding will be PrintableString
or, if a non-printable character is specified, then as either IA5String
or T61String
- see Specifying Distinguished Names for more details. The encoding of the issuer's DN will be exactly as in the issuer's certficate.
If the PKI_X509_AUTHKEYID
flag is set then an authorityKeyIdentifer
extension will be set if there is a corresponding subjectKeyIdentifer
in the issuer's certificate. Otherwise no such extension will be set.
The default validity period is from one minute ago by the system clock for a period of a whole number of years set by the nYearsValid parameter. This time will always have the seconds set to 01. A different validity period can be set using the notBefore
and notAfter
attributes in the szExtensions parameter (see X509 Extensions Parameter).
The serial number can be set to be an integer in the range 1 to 2,147,483,647 using the nCertNum parameter, or (once you have used these up!) it can be set to a larger value, perhaps a random large integer represented by a hexadecimal string, using the serialNumber
attribute in the szExtensions parameter (see X509 Extensions Parameter).
As an alternative, you can create a new X.509 certificate using a PKCS-10 certificate signing request (CSR) file. Pass the name of the CSR file in the szSubjectPubKeyFile parameter and set the szDistName empty ""
. The empty distinguished name parameter is a flag that a CSR file is being used. See the example below.
[New in v12.0] Added support for unencrypted private key files for szIssuerPriKeyFile as well as encrypted ones. Specify szPassword=""
to flag an unencrypted key.
[New in v12.0] Added support for RSA-PSS and ECDSA signatures. Both the signing key and the subject's public key must be either both RSA keys for the RSA options, or both EC keys for the ECDSA signature options. The MGF hash function for RSA-PSS signatures in an X.509 certificate is always the same as the signature hash function. The signing key must be long enough to include the specified digest value and other encoding bytes. For example, a 1024-bit RSA key is too short to sign using RSA-PSS-SHA512 (see RSA signature and encryption schemes). Not all signature options provided may be accepted by other applications. Note also that both these signature schemes are probabilistic and each new signature contains randomly generated salt values, so you won't reproduce the same certificate even with identical inputs. Use the specialist options PKI_PSS_SALTLEN_ZERO
and PKI_SIG_DETERMINISTIC
with RSA-PSS and ECDSA, respectively, to force a deterministic (fixed) result.
[New in v12.3] Added ability to specify an empty subjectName, to set extKeyUsage extension purposes in the X.509 Extensions Parameter, and mark an arbitrary extension as critical. Setting szDistName = "$"
will create an X.509 document with an empty subjectName. At least one field for a subject alternative name extension (altSubjectName
) must be specified and the extension will automatically be marked critical.
char *dn = "$"; char *extns = "iPAddress=192.168.15.1;extKeyUsage=serverAuth,clientAuth,emailProtection,critical;";
[New in v20.5] Added ability to pass an internal key string for the subject's public key and signer's private key.
long X509_MakeCertSelf | ( | const char * | szNewCertFile, |
const char * | szPriKeyFile, | ||
long | nCertNum, | ||
long | nYearsValid, | ||
const char * | szDistName, | ||
const char * | szExtensions, | ||
long | nKeyUsageFlags, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Creates a self-signed X.509 certificate.
[in] | szNewCertFile | Name of new certificate file to be created. | ||||||||||||||||||
[in] | szPriKeyFile | Name of issuer's private key file (encrypted or unencrypted) or a PEM string containing the key, or a valid internal key string. | ||||||||||||||||||
[in] | nCertNum | Serial number for new certificate. Ignored if serialNumber is set in szExtensions. | ||||||||||||||||||
[in] | nYearsValid | Number of years certificate is to be valid starting at current date and hour (can be changed with szExtensions). | ||||||||||||||||||
[in] | szDistName | Distinguished name string (required). See Specifying Distinguished Names for more details. | ||||||||||||||||||
[in] | szExtensions | Extensions: optional list of attribute-value pairs separated by semicolons (;). See X.509 Extensions Parameter. Specify "" or NULL to ignore. | ||||||||||||||||||
[in] | nKeyUsageFlags | Flags to set Key Usage extensions:
| ||||||||||||||||||
[in] | szPassword | containing password for Issuer's encrypted private key file. Specify the empty string "" if key not encrypted [New in v12.0]. | ||||||||||||||||||
[in] | nOptions | Option flags. Choose one signature algorithm from:PKI_SIG_SHA1RSA (0) to use sha1WithRSAEncryption (default - CAUTION)PKI_SIG_SHA224RSA to use sha224WithRSAEncryption PKI_SIG_SHA256RSA to use sha256WithRSAEncryption [minimum recommended]PKI_SIG_SHA384RSA to use sha384WithRSAEncryption PKI_SIG_SHA512RSA to use sha512WithRSAEncryption PKI_SIG_MD5RSA to use md5WithRSAEncryption [legacy, not recommended]PKI_SIG_MD2RSA to use md2WithRSAEncryption [legacy, definitely not recommended]PKI_SIG_RSA_PSS_SHA1 to use RSA-PSS-SHA1 PKI_SIG_RSA_PSS_SHA224 to use RSA-PSS-SHA224 PKI_SIG_RSA_PSS_SHA256 to use RSA-PSS-SHA256 PKI_SIG_RSA_PSS_SHA384 to use RSA-PSS-SHA384 PKI_SIG_RSA_PSS_SHA512 to use RSA-PSS-SHA512 PKI_SIG_ECDSA_SHA1 to use ecdsaWithSHA1 PKI_SIG_ECDSA_SHA224 to use ecdsaWithSHA224 PKI_SIG_ECDSA_SHA256 to use ecdsaWithSHA256 PKI_SIG_ECDSA_SHA384 to use ecdsaWithSHA384 PKI_SIG_ECDSA_SHA512 to use ecdsaWithSHA512 PKI_SIG_ED25519 to use Ed25519 [New in v20.0]PKI_SIG_ED448 to use Ed448 [New in v22.0]And add any combination of these:- PKI_X509_VERSION1 to generate a Version 1 certificate, i.e. no extensions (default = Version 3).PKI_X509_CA_TRUE to set the basicConstraints subject type to be a CA (default = End Entity)PKI_X509_NO_BASIC to disable the basicConstraints extension (default = include)PKI_X509_UTF8 to encode the subject's DN fields as UTF8String (default = PrintableString)PKI_X509_FORMAT_PEM to save the certificate in PEM format (default = DER-encoded binary)Specialist options:- PKI_PSS_SALTLEN_ZERO to use a zero-length salt in an RSA-PSS signature.PKI_SIG_DETERMINISTIC to use the deterministic digital signature generation procedure of [RFC6979] for an ECDSA signature. |
X509_MakeCert()
. A self-signed certificate has the same Issuer and Subject distinguished name. Add the PKI_X509_UTF8
flag to encode the distinguished names in UTF-8. The BasicConstraints
subject type will always be a CA for a version 3 self-signed certificate, unless explicitly excluded with the PKI_X509_NO_BASIC
flag. long X509_MakeCRL | ( | const char * | szCrlFile, |
const char * | szIssuerCert, | ||
const char * | szIssuerKeyFile, | ||
const char * | szPassword, | ||
const char * | szRevokedCertList, | ||
const char * | szExtensions, | ||
long | nOptions | ||
) |
Creates an X.509 Certificate Revocation List (CRL).
[in] | szCrlFile | with name of new CRL file to be created. |
[in] | szIssuerCert | with name of issuer's X.509 certificate file (or base64 representation). |
[in] | szIssuerKeyFile | with name of issuer's encrypted private key file. |
[in] | szPassword | containing password for issuer's encrypted private key file. |
[in] | szRevokedCertList | with list of revoked certificates in format serialNumber,revocationDate; ... or the empty string "" for no revoked certificates. See the Remarks section below for more details. |
[in] | szExtensions | (optional) containing one or more attribute-value pairs separated by semicolons (; ). Valid attribute-value pairs are:
|
[in] | nOptions | Option flags. Choose one signature algorithm from:PKI_SIG_SHA1RSA (0) to use sha1WithRSAEncryption (default - CAUTION)PKI_SIG_SHA224RSA to use sha224WithRSAEncryption PKI_SIG_SHA256RSA to use sha256WithRSAEncryption [minimum recommended]PKI_SIG_SHA384RSA to use sha384WithRSAEncryption PKI_SIG_SHA512RSA to use sha512WithRSAEncryption PKI_SIG_MD5RSA to use md5WithRSAEncryption [legacy, not recommended]PKI_SIG_MD2RSA to use md2WithRSAEncryption [legacy, definitely not recommended]PKI_SIG_RSA_PSS_SHA1 to use RSA-PSS-SHA1 PKI_SIG_RSA_PSS_SHA224 to use RSA-PSS-SHA224 PKI_SIG_RSA_PSS_SHA256 to use RSA-PSS-SHA256 PKI_SIG_RSA_PSS_SHA384 to use RSA-PSS-SHA384 PKI_SIG_RSA_PSS_SHA512 to use RSA-PSS-SHA512 PKI_SIG_ECDSA_SHA1 to use ecdsaWithSHA1 PKI_SIG_ECDSA_SHA224 to use ecdsaWithSHA224 PKI_SIG_ECDSA_SHA256 to use ecdsaWithSHA256 PKI_SIG_ECDSA_SHA384 to use ecdsaWithSHA384 PKI_SIG_ECDSA_SHA512 to use ecdsaWithSHA512 PKI_SIG_ED25519 to use Ed25519 [New in v20.0]PKI_SIG_ED448 to use Ed448 [New in v22.0]And add any combination of these:- PKI_X509_FORMAT_PEM to save the certificate in PEM format (default = DER-encoded binary)Specialist options:- PKI_PSS_SALTLEN_ZERO to use a zero-length salt in an RSA-PSS signature.PKI_SIG_DETERMINISTIC to use the deterministic digital signature generation procedure of [RFC6979] for an ECDSA signature. |
serialNumber,revocationDate;serialNumber,revocationDate; ...
The serialNumber must either be a positive decimal number (e.g. 123
) or the number in hex format preceded by "#x"
(e.g. "#x0102deadbeef"
). The revocation date must be in ISO date format (e.g. 2009-12-31
or 2009-12-31T12:59:59Z
).
By default, the lastUpdate
time in the CRL is set to the time given by the system clock, and nextUpdate
time is left empty. You can specify your own times using the lastUpdate
and nextUpdate
attributes in the szExtensions parameter. Times, if specified, must be in ISO 8601 format and are always interpreted as GMT times whether or not you add a "Z".
long X509_QueryCert | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szCertFile, | ||
const char * | szQuery, | ||
long | nOptions | ||
) |
Queries an X.509 certificate file for selected information.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the length of the output string. |
[in] | szCertFile | with name of X.509 certificate file (or base64 representation). |
[in] | szQuery | specifying the query (see Remarks below). |
[in] | nOptions | option flags: PKI_DEFAULT (0) for default optionsPKI_QUERY_GETTYPE to return the type of data returned for a given query.PKI_X509_LATIN1 to try and convert Unicode/UTF-8/T.61 attribute strings to Latin-1 (ISO-8859-1)PKI_X509_UTF8 to output attribute strings encoded in UTF-8 [New in v20.3]PKI_X509_LDAP to output the distinguished name in LDAP string representation (for queries "issuerName" and "subjectName" only) PKI_X509_DECIMAL to output the serial number in decimal format instead of hex (for query "serialNumber" only) |
Query String | Returns | Data Type |
---|---|---|
version | X.509 version number, e.g. 1 or 3. | Number |
serialNumber | Serial number in hex-encoded format | String |
signatureAlgorithm | Signature algorithm used, e.g. "sha1WithRSAEncryption" . | String |
sigAlgId | ID of signature algorithm used, see PKI_SIG_* values | Number |
signatureValue | Signature value in hex-encoded format | String |
notBefore | Date on which the certificate validity period begins in format yyyy-mm-ddThh:nn:ssZ | String |
notAfter | Date on which the certificate validity period ends in format yyyy-mm-ddThh:nn:ssZ | String |
issuerName | Distinguished name (DN) of entity who has signed and issued the certificate | String |
subjectName | Distinguished name (DN) of the subject | String |
subjectPublicKeyAlgorithm | Algorithm used in subject's public key, e.g. "dsa" or "rsaEncryption" . | String |
subjectKeyIdentifier | The subject key identifier extension, if present, in hex-encoded format | String |
authorityKeyIdentifier | The authority key identifier extension, if present, in hex-encoded format | String |
rfc822Name | First internet mail address found contained in a subjectAltName extension, if present | String |
isCA | Returns 1 if the subject type is a CA, otherwise returns 0. | Number |
keyUsageString | keyUsage flags in text format, e.g. "digitalSignature,nonRepudiation" | String |
extKeyUsageString | extKeyUsage purposes in text format, e.g. "codeSigning,timeStamping" | String |
cRLDistributionPointsURI | First URI found in cRLDistributionPoints , if any | String |
authorityInfoAccessURI | First URI found in authorityInfoAccess , if any | String |
subjectAltName | Subject alternative name extension, if present. [New in v10.0] | String |
hashAlgorithm | Hash algorithm used in signature, e.g. "sha256" . [New in v12.0] | String |
pssParams | Parameters used for RSA-PSS (if applicable). [New in v12.0] | String |
Some of these queries duplicate or complement existing functions:
"notBefore"
= X509_CertIssuedOn()
"notAfter"
= X509_CertExpiresOn()
"serialNumber"
= X509_CertSerialNumber()
"subjectName"
= X509_CertSubjectName()
"issuerName"
= X509_CertIssuerName()
The "raw" VBA/C function behaves differently depending on whether the output is a string or a number. If the result data type is a number then it returns the value directly. If the result is a string, then it sets szOutput and returns the number of characters in the string. The required number of characters can be found by passing zero for nOutChars or a null string for szOutput. ANSI C users must add one to this value when allocating memory.
Note that the VBA wrapper function and the C#/VB.NET methods always return a string, which is different from the behaviour of the raw VB6/C function.
To find out the type of data returned for a given query, use the PKI_QUERY_GETTYPE
option. The function will return either PKI_QUERY_NUMBER
(1) or PKI_QUERY_STRING
(2), or a negative "invalid query" error. For example
nRet = X509_QueryCert("", 0, "", "version", PKI_QUERY_GETTYPE);
will return PKI_QUERY_NUMBER
.
If an attribute value is encoded in a multi-byte-character string format (such as UTF8String or BMPString), the value will be expressed as a hexadecimal-encoded string [NB changed in v3.9] preceded by the hash symbol ('#'
U+0023), e.g.
"C=TW;<span class="withdrawn">O=E8 A1 8C E6 94 BF E9 99 A2</span>" (v3.8 and earlier) "C=TW;O=#E8A18CE694BFE999A2" (v3.9 and later)
Use the PKI_X509_LATIN1
option to return the string encoded in Latin-1, if possible, to help with display issues.
The output from the queries "issuerName"
and "subjectName"
using the PKI_X509_LDAP
option are suitable as content for the <X509IssuerName>
and <X509SubjectName>
nodes, respectively, in the <X509Data>
node of an XML-DSIG document.
long X509_ReadCertStringFromP7Chain | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szP7cFile, | ||
long | nIndex, | ||
long | nOptions | ||
) |
Reads an X.509 certificate into a base64 string from PKCS-7 "certs-only" data.
[out] | szOutput | string buffer to receive the output. |
[in] | nOutChars | size of the output buffer in bytes. |
[in] | szP7cFile | filename of a PKCS-7 "certs-only" file, or a string containing its PEM textual representation. |
[in] | nIndex | specifying which certificate (1,2,...) in the chain to extract, or (deprecated) 0 to return the count of certificates in the set. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
The output is a base64 string representation of the extracted X.509 certificate.
If nIndex is specified as a number greater than zero, the nIndex'th certificate found in the list, if any, will be extracted to a base64-encoded string which can be used to represent the X.509 certificate directly in this Toolkit.
This function will also extract certificates from CMS signed data objects, too.
[New in v12.2] To find the number of certificates in the chain, use X509_GetCertCountInP7Chain. The old (deprecated) way to find the count of certificates was to set nIndex to zero.
long X509_ReadCertStringFromPFX | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szPfxFile, | ||
const char * | szPassword, | ||
long | nOptions | ||
) |
Reads an X.509 certificate into a base64 string from PKCS-12 PFX/.p12 data.
[out] | szOutput | string buffer to receive the output. |
[in] | nOutChars | size of the output buffer in bytes. |
[in] | szPfxFile | filename of a PFX file, or a string containing its PEM textual representation. |
[in] | szPassword | containing password or "" if certificate is not encrypted |
[in] | nOptions | option flags: not used in this release. Specify zero. |
The default behaviour is to extract one certificate from the PFX file and output as a base64 string representation of the extracted X.509 certificate. It will attempt to find a matching certificate for any private key, otherwise it will save the first pkcs-12-certBag
found in the PFX file containing a x509Certificate
.
Both unencrypted certificates and certificates encrypted with the weak 40-bit encryption used by "default" in Microsoft and OpenSSL PKCS-12 files are supported, but not any other encryption algorithm.
If no certificate can be found the function will return a negative NO_DATA_ERROR
error code.
long X509_ReadStringFromFile | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szCertFile, | ||
long | nOptions | ||
) |
Creates a base64 string of an X.509 certificate file.
[out] | szOutput | to receive the output. |
[in] | nOutChars | specifying the length of the output string. |
[in] | szCertFile | with name of X.509 certificate file. |
[in] | nOptions | option flags: not used. Set to zero. |
This function reads in the complete X.509 certificate as a continuous base64 string. The same certificate will always produce exactly the same string. This string can be used, for example, when creating an XML file which requires the certificate as an attribute, e.g.
<?xml version="1.0" encoding="UTF-8"?>
<Comprobante fecha="2005-09-02T16:30:00" folio="1" noAprobacion="1"
noCertificado="00001000000000000114"
certificado="MIIDWjCCAkKgAwIBAgIUMDAwMDExMDAwMDAyMDA..."
serie="A" version="1.0">
The output string must be long enough to receive the complete output or a SHORT_BUF_ERROR
error will result.
long X509_SaveFileFromString | ( | const char * | szNewCertFile, |
const char * | szCertString, | ||
long | nOptions | ||
) |
Creates an X.509 certificate file from its base64 string representation.
[in] | szNewCertFile | with name of X.509 certificate file to be created. |
[in] | szCertString | containing the base64 representation of the certificate. |
[in] | nOptions | option flags: PKI_X509_FORMAT_PEM to save the certificate in PEM format (default = DER-encoded binary) |
X509_ReadStringFromFile()
. Any existing file of the same name will be overwritten without warning. The default option (nOptions = 0
) is to save the file in binary (BER, DER) format. A PEM format file will start with --—BEGIN CERTIFICATE--—
and will contain the same base64 characters as in the certificate string. Both formats should be equally readable with the usual certificate manager programs and both should have the same message digest "thumbprint". long X509_TextDump | ( | const char * | szFileOut, |
const char * | szCertFile, | ||
long | nOptions | ||
) |
Dumps details of an X.509 certificate (or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR)) to a text file.
[in] | szFileOut | with the filename of text file to be created. |
[in] | szCertFile | with the filename of Certificate file (or base64 representation). |
[in] | nOptions | option flags:PKI_X509_LATIN1 to try and convert UTF-8 attribute strings to Latin-1 (for display purposes).PKI_X509_UTF8 to output attribute strings encoded in UTF-8 [New in v20.3]PKI_X509_LDAP to output the distinguished name in LDAP string representation. PKI_X509_DECIMAL to output the serial number in decimal format instead of hexadecimal. |
[New in v12.3] The notation [!]
denotes a critical extension, e.g. Key Usage[!]:
.
long X509_TextDumpToString | ( | char * | szOutput, |
long | nOutChars, | ||
const char * | szCertFile, | ||
long | nOptions | ||
) |
Dumps details of an X.509 certificate or a X.509 certificate revocation list (CRL) or a PKCS-10 certificate signing request (CSR) to a string.
[out] | szOutput | String buffer to receive output. |
[in] | nOutChars | Maximum number of characters to be received. |
[in] | szCertFile | Name of input file (or its base64 or PEM string representation). |
[in] | nOptions | option flags:PKI_X509_LATIN1 to try and convert UTF-8 attribute strings to Latin-1 (for display purposes).PKI_X509_UTF8 to output attribute strings encoded in UTF-8 (C/C++ only) [New in v20.3]PKI_X509_LDAP to output the distinguished name in LDAP string representation. PKI_X509_DECIMAL to output the serial number in decimal format instead of hexadecimal. |
The input file may be a an X.509 certificate, X.509 certificate revocation list (CRL) or PKCS-10 certificate signing request (CSR) and may be a file in binary BER/DER or base64 PEM file format, or may be passed in base64 representation or as a PEM string.
The output string must be long enough to receive the complete output or a SHORT_BUF_ERROR
error will result.
long X509_ValidatePath | ( | const char * | szCertListOrP7File, |
const char * | szTrustedCert, | ||
long | nOptions | ||
) |
Validates a certificate path.
[in] | szCertListOrP7File | either a list of certificate names separated by a semicolon or the name of a PKCS-7 "certs-only" file containing the certificates to be validated. |
[in] | szTrustedCert | name of the trusted certificate (or base64 representation). |
[in] | nOptions | option flags: PKI_X509_NO_TIMECHECK to avoid checking if the certificates are valid now (default = check validity dates against system clock). |
x
is the issuer of certificate x+1
, that certficate x
was signed by certificate x-1
, and that each certificate is valid as at the time on the system clock. Only distinguished names are used to identify subjects and issuers, not alternative names or IDs. Certificate policies are ignored and no checks are made for revocation (use X509_CheckCertInCRL()
individually). The order of the certificates in the input list is not important, but a complete chain must exist. Note that the certificates must either all exist inside one .p7c cert chain file, or exist individually as .cer files. In the latter case, specify all the file names in a semi-colon-separated list. You can also pass the individual certificate information in its base64 representation rather than filenames, as in szCertList="MIHgMIGaAgE...se348UN/Q=;MIHgMIGaAgEB...9j8eEtvHw=;...etc
.The szTrustedCert parameter is required unless a self-signed trust anchor is included in the list. If there is no self-signed certificate, then you must specify a trusted certificate which has signed the certificate at the top of your chain. If specified, this must exist separately as a .cer file.
All certificates must be valid at the time the check is made or an error will result, unless the PKI_X509_NO_TIMECHECK
option is used. More information on the reason for an invalid certification path may be available by using PKI_LastError()
.
[Changed in v12.0] If the certificates are otherwise of correct format but the validation fails, this function returns CERT_PATH_ERROR
(+43). Previous versions would return +1.
long X509_VerifyCert | ( | const char * | szCertToVerify, |
const char * | szIssuerCert, | ||
long | nOptions | ||
) |
Verifies that an X.509 certificate - or X.509 certificate revocation list (CRL) or PKCS-10 certificate signing request (CSR) - has been signed by its issuer.
[in] | szCertToVerify | Name of the file to be verified (or a PEM string). |
[in] | szIssuerCert | Name of the issuer's certificate file (or a PEM string). Leave empty "" for a PKCS#10 CSR. |
[in] | nOptions | option flags: not used in this release. Specify zero. |
X509_CertIsValidNow()
). Nor does it check that the certficate has been revoked (to do that use X509_CheckCertInCRL()
). Only certificates signed with supported signature algorithms can be checked: see Supported Algorithms. The certificate file may be in binary BER/DER format or base64 PEM file format, or may be passed in base64 representation or as a PEM string.This function can also be used to verify that an X.509 Certificate Revocation List (CRL) has been signed by the owner of the issuer's certificate or that the self-signed signature in a PKCS#10 Certificate Signing Request (CSR) is valid. Just pass the name of the file (or its PEM string form) as szCertToVerify.
[New in v12.0] A PKCS#10 Certificate Signing Request (CSR) contains its own public key which it can use to verify its own signature directly. To verify a CSR, pass its name in szCertToVerify and set szIssuerCert=""
. See example below.
[Changed in v12.0] If the certificate is otherwise of correct format but the validation fails, this function returns SIGNATURE_ERROR
(22). Previous versions would return -1.
long XOF_Bytes | ( | unsigned char * | lpOutput, |
long | nOutBytes, | ||
const void * | lpMessage, | ||
long | nMsgLen, | ||
long | nOptions | ||
) |
Generate bytes using an extendable output function (XOF).
[out] | lpOutput | byte buffer to receive the output. |
[in] | nOutBytes | size of output buffer in bytes. |
[in] | lpMessage | byte array containing the input data. |
[in] | nMsgLen | length of the input data in bytes. |
[in] | nOptions | Option flags. Select one of:PKI_XOF_SHAKE128 to use SHAKE128PKI_XOF_SHAKE256 to use SHAKE256PKI_XOF_MGF1_SHA1 to use MGF1-SHA-1PKI_XOF_MGF1_SHA256 to use MGF1-SHA-256PKI_XOF_MGF1_SHA512 to use MGF1-SHA-512 |
SHAKE128 and SHAKE256 are described in [FIPS202]. MGF1, despite its name as a Mask Generation Function (MGF), is also an eXtendable Output Function (XOF) using the SHA1/SHA-2 hash functions, and is described in [PKCS1].