Initialize the CIPHER context with the key, iv, algorithm and mode ready for repeated update operations.
Public Declare Function CIPHER_Init Lib "diCryptoSys.dll" (ByVal fEncrypt As Integer, ByVal strAlgAndMode As String, ByRef lpKey As Byte, ByVal nKeyLen As Long, ByRef lpIV As Byte, ByVal nIvLen As Long, ByVal nOptions As Long) As Long
hContext = CIPHER_Init(fEncrypt, strAlgAndMode, lpKey(0), nKeyLen, lpIV(0), nIvLen, nOptions)
long __stdcall CIPHER_Init(int fEncrypt, const char *szAlgAndMode, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, long nOptions);
"aes128/cbc"
(see Specifying the algorithm and mode for generic block cipher functions). Non-zero handle of the CIPHER context, or zero if an error occurs.
Public Function cipherInit
(fEncrypt As Integer, szAlgAndMode As String, lpKey() As Byte, lpIV() As Byte, Optional nOptions As Long = 0) As Long
Cipher.InitEncrypt Method (Byte[], Byte[], CipherAlgorithm, Mode)
Cipher.InitDecrypt Method (Byte[], Byte[], CipherAlgorithm, Mode)
bool crsysapi::Cipher::InitDecrypt (const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode)
bool crsysapi::Cipher::InitEncrypt (const bvec_t &key, const bvec_t &iv, Alg alg, Mode mode)
The key must be of the exact key length required for the cipher algorithm. The IV, if provided, must be exactly the length of the cipher block (16 bytes for AES, 8 bytes for Triple DES).
See CIPHER_Update
.
Example showing an error
Dim hContext As Long hContext = cipherInit(ENCRYPT, "BADALG", cnvBytesFromHexStr("0123456789ABCDEFF0E1D2C3B4A59687"), cnvBytesFromHexStr("")) Debug.Print "cipherInit returns 0x" & Hex(hContext) & " (0 => error)" Debug.Print "ErrorCode=" & API_ErrorCode() & ": " & apiErrorLookup(API_ErrorCode())
cipherInit returns 0x0 (0 => error) ErrorCode=6: Parameter is wrong or missing (BAD_PARAM_ERROR)
CIPHER_InitHex
CIPHER_Update
CIPHER_UpdateHex
CIPHER_Final