Initializes the context with the key ready for repeated operations of
GCM_NextEncrypt
and
GCM_NextDecrypt
.
Public Declare Function GCM_InitKey Lib "diCryptoSys.dll" (ByRef lpKey As Byte, ByVal nKeyLen As Long, ByVal nOptions As Long) As Long
nRet = GCM_InitKey(abKey(0), nKeyLen, nOptions)
long __stdcall GCM_InitKey(const unsigned char *lpKey, long nKeyLen, long nOptions);
non-zero handle of the GCM context hContext
. Returns zero if an error occurs.
It is important to check for a zero context handle and stop if one occurs.
Dim abKey() As Byte Dim nKeyLen As Long Dim hContext As Long Dim nCode As Long ' Initialise with a valid key abKey = cnvBytesFromHexStr("feffe9928665731c6d6a8f9467308308") nKeyLen = UBound(abKey) + 1 hContext = GCM_InitKey(abKey(0), nKeyLen, 0) Debug.Print "GCM_InitKey returns " & Hex(hContext) & " (expected non-0)" If hContext <> 0 Then '... do something here... ' Destroy the key Call GCM_FinishKey(hContext) End If ' Now try an invalid key (length must be 16,24, or 32 bytes) abKey = cnvBytesFromHexStr("badace") nKeyLen = UBound(abKey) + 1 hContext = GCM_InitKey(abKey(0), nKeyLen, 0) Debug.Print "GCM_InitKey returns " & Hex(hContext) ' Use API_ErrorCode to find the error value nCode = API_ErrorCode() Debug.Print "API_ErrorCode returns " & nCode & ": " & apiErrorLookup(nCode)
This should result in output as follows:
GCM_InitKey returns 3C8D3BD3 (expected non-0) GCM_InitKey returns 0 API_ErrorCode returns 33: Invalid key length (BAD_KEY_LEN_ERROR)
GCM_NextEncrypt
GCM_NextDecrypt