Encrypts or decrypts data represented as a base64 string using a specified mode. The key and initialization vector are represented as base64 strings.
Public Declare Function AES256_B64Mode Lib "diCryptoSys.dll"
(ByVal strOutput As String, ByVal strInput As String,
ByVal strKey As String, ByVal bEncrypt As Boolean,
ByVal strMode As String, ByVal strIV As String) As Long
nRet = AES256_B64Mode(strOutput, strInput, strKey, bEncrypt, strMode, strIV)
long __stdcall AES256_B64Mode(char *szOutput, const char *szInput, const char *szKey, int fEncrypt, const char *szMode, const char *szIV);
If successful, the return value is 0; otherwise it returns a non-zero error code.
Aes256.Encrypt Method (String, String, Mode, String, EncodingBase)
Aes256.Decrypt Method (String, String, Mode, String, EncodingBase)
The length of the input string szInput must represent a multiple of the block size (16 bytes) when decoded.
If not, an error will be returned.
The initialization vector
string szIV must represent exactly 16 bytes
unless szMode is ECB, in which case szIV is ignored (use ""
).
The key szKey must represent exactly 32 bytes, the required key length.
The output string szOutput must be set up with at least the same
number of characters as the input string before calling.
The variables szOutput and szInput should be different.
This example is the same data as for AES256_HexMode
,
except the data is in base64 format.
Dim nRet As Long Dim strOutput As String Dim strInput As String Dim strKey As String Dim strIV As String Dim bEncrypt As Boolean Dim sCorrect As String strInput = "oKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/" _ & "AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3w==" strKey = "VuR6OMVZiXS8RpA9uikDSQapIUA2uKFbUS4D1TQSAAY=" strIV = "jOgu776g2jxEaZ7X21G32Q==" sCorrect = "KECaKYK9LPfONDp9Q/aSf9uexTK7pWnuyS5XognE/" _ & "bpZrboFpchUaU3cn3mRwBY05yvrT+AjbLOxGaRjiR40bw==" ' Set strOutput to be same length as strInput strOutput = String(Len(strInput), " ") Debug.Print "KY=" & strKey Debug.Print "IV=" & strIV Debug.Print "PT=" & strInput nRet = AES256_B64Mode(strOutput, strInput, strKey, ENCRYPT, "CBC", strIV) Debug.Print "CT=" & strOutput; nRet Debug.Print "OK=" & sCorrect strInput = strOutput nRet = AES256_B64Mode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV) Debug.Print "P'=" & strOutput; nRet
This should result in output as follows:
KY=VuR6OMVZiXS8RpA9uikDSQapIUA2uKFbUS4D1TQSAAY= IV=jOgu776g2jxEaZ7X21G32Q== PT=oKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/A wcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3w== CT=KECaKYK9LPfONDp9Q/aSf9uexTK7pWnuyS5XognE/bpZ rboFpchUaU3cn3mRwBY05yvrT+AjbLOxGaRjiR40bw== 0 OK=KECaKYK9LPfONDp9Q/aSf9uexTK7pWnuyS5XognE/bpZ rboFpchUaU3cn3mRwBY05yvrT+AjbLOxGaRjiR40bw== P'=oKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/A wcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3w== 0
AES256_HexMode
AES256_BytesMode