Enciphers data in a hex-encoded string using specified stream cipher.
Public Declare Function CIPHER_StreamHex Lib "diCryptoSys.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strInputHex As String, ByVal strKeyHex As String, ByVal strIvHex As String, ByVal nCounter As Long, ByVal nOptions As Long) As Long
nRet = CIPHER_StreamHex(strOutput, nOutChars, strInputHex, strKeyHex, strIvHex, nCounter, nOptions)
long __stdcall CIPHER_StreamHex(char *szOutput, long nOutChars, const char *szInputHex, const char *szKeyHex, const char *szIvHex, long nCounter, long nOptions);
""
for Arcfour.If successful, the return value is zero; otherwise it returns a nonnegative error code.
Public Function cipherStreamHex
(lpInput() As Byte, lpKey() As Byte, lpIV() As Byte, nOptions As Long, Optional nCounter As Long = 0) As String
This performs a one-off encryption of data in a hex-encoded string using the specified stream cipher. The key and IV are passed as hex-encoded strings. The output will be exactly the same length as the input. C/C++ users must add one to this value when allocating memory.
""
for IV.' Ref: eSTREAM `verified.test-vectors.txt` Set 3, vector# 0: Dim nRet As Long Dim strKey As String Dim strIV As String Dim strInput As String Dim strOutput As String Dim strCorrect As String Dim strCheck As String ' Parameters are hex-encoded strings strKey = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" strIV = "0000000000000000" ' Key stream is generated by encrypting 32 zero bytes (=64 hex chars) strInput = "0000000000000000000000000000000000000000000000000000000000000000" strCorrect = "B580F7671C76E5F7441AF87C146D6B513910DC8B4146EF1B3211CF12AF4A4B49" Debug.Print "KY=" & strKey Debug.Print "IV=" & strIV Debug.Print "PT=" & strInput ' Encipher using Salsa20 in hex mode strOutput = String(Len(strInput), " ") nRet = CIPHER_StreamHex(strOutput, Len(strOutput), strInput, strKey, strIV, 0, API_SC_SALSA20) Debug.Print "CT=" & strOutput Debug.Print "OK=" & strCorrect
This should result in output as follows:
KY=000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F IV=0000000000000000 PT=0000000000000000000000000000000000000000000000000000000000000000 CT=B580F7671C76E5F7441AF87C146D6B513910DC8B4146EF1B3211CF12AF4A4B49 OK=B580F7671C76E5F7441AF87C146D6B513910DC8B4146EF1B3211CF12AF4A4B49
Dim strCipher As String Dim strPlain As String strCipher = cipherStreamHex("0000000000000000000000000000000000000000000000000000000000000000", _ "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", _ "0000000000000000", API_SC_SALSA20) Debug.Print "CT=" & strCipher Debug.Print "OK=B580F7671C76E5F7441AF87C146D6B513910DC8B4146EF1B3211CF12AF4A4B49" ' Decrypt by calling again... strPlain = cipherStreamHex(strCipher, _ "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", _ "0000000000000000", API_SC_SALSA20) Debug.Print "PT=" & strPlain strCipher = cipherStreamHex("00000000000000000000", _ "ef012345", "", API_SC_ARCFOUR) Debug.Print "CT=" & strCipher Debug.Print "OK=d6a141a7ec3c38dfbd61" ' Decrypt by calling again... strPlain = cipherStreamHex(strCipher, _ "ef012345", "", API_SC_ARCFOUR) Debug.Print "PT=" & strPlain
CIPHER_StreamBytes
CIPHER_StreamInit