Encrypts or decrypts data represented as a hexadecimal string using a specified mode. The key and initialization vector are represented as a hexadecimal string.
Public Declare Function TDEA_HexMode Lib "diCrPKI.dll"
(ByVal strOutput As String, ByVal strInput As String, ByVal strKey As String,
ByVal fEncrypt As Long, ByVal strMode As String, ByVal strIV As String) As Long
nRet = TDEA_HexMode(strOutput, strInput, strKey, fEncrypt, strMode, strIV)
String of sufficient length to receive the output.String containing the input data in hex format.String containing the key in hex format.Boolean direction flag:
set as ENCRYPT (True) to encrypt or DECRYPT (False)
to decrypt.String specifying the confidentiality mode:String containing the initialization vector (IV), if required,
in hex format.
long _stdcall TDEA_HexMode(char *szOutput, const char *szInput, const char *szKey, long fEncrypt, const char *szMode, const char *szIV);
Long: If successful, the return value is zero;
otherwise it returns a nonzero error code.
Tdea.Encrypt Method (String, String, Mode, String)
Tdea.Decrypt Method (String, String, Mode, String)
For ECB and CBC modes, the length of the input string strInput must be a multiple of 16 hex characters long
(i.e. representing a multiple of 8 bytes) otherwise an error will result.
The key string strKey
must be exactly 48 hex characters long (i.e. representing exactly 24 bytes/192 bits).
The initialization vector
string strIV must be exactly 16 hex characters long
(i.e. representing exactly the block size of 8 bytes) unless strMode is ECB,
in which case strIV is ignored (use "").
Valid hexadecimal characters are [0-9A-Fa-f].
The output string strOutput must be set up with the same
number of characters as the input string before calling.
The variables strOutput and strInput should be different.
This example is from Section 8.1 of [SMIME-EX].
Dim nRet As Long Dim sOutput As String Dim sInput As String Dim sKey As String Dim sInitV As String Dim sCorrect As String sInput = "5468697320736F6D652073616D706520636F6E74656E742E0808080808080808" ' T h i s _ s o m e _ s a m p e _ c o n t e n t . (padding 8 x 08) sKey = "737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32" sInitV = "B36B6BFB6231084E" sCorrect = "d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4" ' Set sOutput to be same length as sInput sOutput = String(Len(sInput), " ") Debug.Print "KY=" & sKey Debug.Print "PT=" & sInput nRet = TDEA_HexMode(sOutput, sInput, sKey, ENCRYPT, "CBC", sInitV) Debug.Print "CT=" & sOutput & nRet Debug.Print "OK=" & sCorrect sInput = sOutput nRet = TDEA_HexMode(sOutput, sInput, sKey, DECRYPT, "CBC", sInitV) Debug.Print "P'=" & sOutput & nRet
This should result in output as follows:
KY=737C791F25EAD0E04629254352F7DC6291E5CB26917ADA32 PT=5468697320736F6D652073616D706520636F6E74656E742E0808080808080808 CT=D76FD1178FBD02F84231F5C1D2A2F74A4159482964F675248254223DAF9AF8E4 0 OK=d76fd1178fbd02f84231f5c1d2a2f74a4159482964f675248254223daf9af8e4 P'=5468697320736F6D652073616D706520636F6E74656E742E0808080808080808 0