Enciphers an array of Bytes in one step using the RC4-compatible 'PC1' algorithm.
Public Declare Function PC1_Bytes Lib "diCryptoSys.dll"
(ByRef lpOutput As Byte, ByRef lpData As Byte, ByVal nDataLen As Long,
ByRef lpKey As Byte, ByVal nKeyLen As Long) As Long
nRet = PC1_Bytes(lpOutput(0), abData(0), nDataLen, abKey(0), nKeyLen)
' Note the "(0)" after the byte array parameters
long __stdcall PC1_Bytes(unsigned char *lpOutput, unsigned char *lpInput, long nBytes, unsigned char *lpKey, long nKeyBytes);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Pc1.Encrypt Method (Byte[], Byte[])
pc1.EncryptHex
Public Function EncryptHex(ByVal sInputHex As String, ByVal strHexKey As String) As String
See pc1.EncryptHex
.
The input data lpData can be of any length provided lpOutput is at least as long. The key lpKey can be any length. lpOutput and lpData may be the same.
Dim abKey() As Byte Dim abInput() As Byte Dim lpOutput() As Byte Dim nRet As Long Dim nDataLen As Long Dim nKeyLen As Long Dim sCorrect As String abKey = cnvBytesFromHexStr("0123456789abcdef") abInput = cnvBytesFromHexStr("0123456789abcdef") sCorrect = "75b7878099e0c596" ReDim lpOutput(UBound(abInput)) nDataLen = UBound(abInput) - LBound(abInput) + 1 nKeyLen = UBound(abKey) - LBound(abKey) + 1 Debug.Print "KY=" & cnvHexStrFromBytes(abKey) Debug.Print "PT=" & cnvHexStrFromBytes(abInput) ' Encipher using PC1 nRet = PC1_Bytes(lpOutput(0), abInput(0), nDataLen, abKey(0), nKeyLen) Debug.Print "CT=" & cnvHexStrFromBytes(lpOutput) Debug.Print "OK=" & sCorrect ' Now decipher just by calling again. Use same output as input. nRet = PC1_Bytes(lpOutput(0), lpOutput(0), nDataLen, abKey(0), nKeyLen) Debug.Print "P'=" & cnvHexStrFromBytes(lpOutput)
This should result in output as follows:
KY=0123456789ABCDEF PT=0123456789ABCDEF CT=75B7878099E0C596 OK=75b7878099e0c596 P'=0123456789ABCDEF