CryptoSys API Library Manual

CIPHER_Init

Initialize the CIPHER context with the key, iv, algorithm and mode ready for repeated update operations.

VBA/VB6 Syntax

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)

C/C++ Syntax

long __stdcall CIPHER_Init(int fEncrypt, const char *szAlgAndMode, const unsigned char *lpKey, long nKeyLen, const unsigned char *lpIV, long nIvLen, long nOptions);

Parameters

fEncrypt
[in] Direction flag: set as ENCRYPT (True) to encrypt or DECRYPT (False) to decrypt.
szAlgAndMode
[in] String specifying the block cipher algorithm and mode, e.g. "aes128/cbc" (see Specifying the algorithm and mode for generic block cipher functions).
lpKey
[in] Key of exact length for block cipher algorithm.
nKeyLen
[in] Length of key in bytes.
lpIV
[in] Initialization Vector (IV) of exactly the block size, or zero (0) for ECB mode.
nIvLen
[in] Length of IV in bytes.
nOptions
[in] Option flags: zero (0) for default options.

Returns (VBA/C)

Non-zero handle of the CIPHER context, or zero if an error occurs.

VBA Wrapper Syntax

Public Function cipherInit(fEncrypt As Integer, szAlgAndMode As String, lpKey() As Byte, lpIV() As Byte, Optional nOptions As Long = 0) As Long

.NET Equivalent

Cipher.InitEncrypt Method (Byte[], Byte[], CipherAlgorithm, Mode)
Cipher.InitDecrypt Method (Byte[], Byte[], CipherAlgorithm, Mode)

C++ (STL) Equivalent

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)

Remarks

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).

Example

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)

See Also

CIPHER_InitHex CIPHER_Update CIPHER_UpdateHex CIPHER_Final

[Contents] [Index]

[PREV: CIPHER_Final...]   [Contents]   [Index]   
   [NEXT: CIPHER_InitHex...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.