Encrypts or decrypts data represented as a hexadecimal string using a key represented in hexadecimal notation. The process is carried out in one step in Electronic Codebook (EBC) mode.
Public Declare Function BLF_Hex Lib "diCryptoSys.dll"
(ByVal strOutput As String, ByVal strInput As String, ByVal strKey As String,
ByVal bEncrypt As Boolean) As Long
nRet = BLF_Hex(strOutput, strInput, strKey, bEncrypt)
String of sufficient length to receive the output.String containing the input data in hexadecimal.String containing the key in hexadecimal.Boolean direction flag:
set as True to encrypt or False
to decrypt.
long _stdcall BLF_Hex(char *strOutput, const char *strInput,
const char *strKey, int bEncrypt);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
The length of the input string strInput must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 bytes). If not, an error code will be returned.. The key strKey can be any even length between 2 and 112 hexadecimal characters. The output string strOutput must be set up with at least the same number of characters as the input string before calling. The variables strOutput and strInput should be different. Valid hexadecimal characters are [0-9A-Fa-f].
Dim nRet As Long
Dim strOutput As String
Dim strInput As String
Dim strKey As String
Dim sCorrect As String
strInput = "0123456789ABCDEF"
strKey = "FEDCBA9876543210"
sCorrect = "0ACEAB0FC6A0A28D"
' Set strOutput to be same length as strInput
strOutput = String(Len(strInput), " ")
Debug.Print "KY="; strKey
Debug.Print "PT="; strInput
' Encrypt in one-off process
nRet = BLF_Hex(strOutput, strInput, strKey, ENCRYPT)
Debug.Print "CT="; strOutput
Debug.Print "OK="; sCorrect
' Now decrypt back to plain text
strInput = strOutput
nRet = BLF_Hex(strOutput, strInput, strKey, DECRYPT)
Debug.Print "P'="; strOutput
This should result in output as follows:
KY=FEDCBA9876543210 PT=0123456789ABCDEF CT=0ACEAB0FC6A0A28D OK=0ACEAB0FC6A0A28D P'=0123456789ABCDEF