Enciphers data encoded in hex format in one step using the RC4-compatible 'PC1' algorithm.
Public Declare Function PC1_Hex Lib "diCryptoSys.dll"
(ByVal strOutput As String, ByVal nMaxChars As Long,
ByVal strInputHex As String, ByVal strKeyHex As String) As Long
nRet = PC1_Hex(strOutput, nMaxChars, strInputHex, strKeyHex)
String to receive the hexadecimal-encoded output.Long specifying the maximum number of characters in strOutput.String containing the input data in hex format.String containing the key in hex format.
long _stdcall PC1_Hex(char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
Pc1.Encrypt Method (String, String)
pc1.EncryptHex
Public Function EncryptHex(ByVal sInputHex As String, ByVal strHexKey As String) As String
See pc1.EncryptHex.
All hex parameters must be an even number of hexadecimal digits. The input data strInputHex can be of any length provided strOutput is at least as long. The key strKeyHex can be any length. strOutput and strInputHex should be different variables.
Dim nRes As Long
Dim strKey As String
Dim strInput As String
Dim strOutput As String
Dim strCorrect As String
Dim strCheck As String
' Test vector 3
strKey = "ef012345"
strInput = "00000000000000000000"
strCorrect = "d6a141a7ec3c38dfbd61"
Debug.Print "KY="; strKey
Debug.Print "PT="; strInput
' Encipher using PC1 in hex mode
strOutput = String(Len(strInput), " ")
nRes = PC1_Hex(strOutput, Len(strOutput), strInput, strKey)
Debug.Print "CT="; strOutput
Debug.Print "OK="; strCorrect
' Now decipher just by calling again.
strCheck = String(Len(strInput), " ")
nRes = PC1_Hex(strCheck, Len(strCheck), strOutput, strKey)
Debug.Print "P'="; strCheck
This should result in output as follows:
KY=ef012345 PT=00000000000000000000 CT=D6A141A7EC3C38DFBD61 OK=d6a141a7ec3c38dfbd61 P'=00000000000000000000