Encrypts or decrypts data represented as a base64 string using a specified mode.
VB6/VBA
Debug.Print "Testing AES128_B64Mode ..." 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 ' Case #4: Encrypting 64 bytes (4 blocks) using AES-CBC with 128-bit key ' Key : 0x56e47a38c5598974bc46903dba290349 strKey = "VuR6OMVZiXS8RpA9uikDSQ==" ' IV : 0x8ce82eefbea0da3c44699ed7db51b7d9 strIV = "jOgu776g2jxEaZ7X21G32Q==" ' Plaintext : 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeaf ' b0b1b2b3b4b5b6b7b8b9babbbcbdbebf ' c0c1c2c3c4c5c6c7c8c9cacbcccdcecf ' d0d1d2d3d4d5d6d7d8d9dadbdcdddedf strInput = "oKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/" _ & "AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3w==" ' Ciphertext: 0xc30e32ffedc0774e6aff6af0869f71aa ' 0f3af07a9a31a9c684db207eb0ef8e4e ' 35907aa632c3ffdf868bb7b29d3d46ad ' 83ce9f9a102ee99d49a53e87f4c3da55 sCorrect = "ww4y/+3Ad05q/2rwhp9xqg868HqaManGhNsgfrDvjk" _ & "41kHqmMsP/34aLt7KdPUatg86fmhAu6Z1JpT6H9MPaVQ==" ' 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 = AES128_B64Mode(strOutput, strInput, strKey, ENCRYPT, "CBC", strIV) Debug.Print "CT=", strOutput, nRet Debug.Print "OK=", sCorrect strInput = strOutput nRet = AES128_B64Mode(strOutput, strInput, strKey, DECRYPT, "CBC", strIV) Debug.Print "P'=", strOutput, nRet
Output
Testing AES128_B64Mode ... KY= VuR6OMVZiXS8RpA9uikDSQ== IV= jOgu776g2jxEaZ7X21G32Q== PT= oKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3w== CT= ww4y/+3Ad05q/2rwhp9xqg868HqaManGhNsgfrDvjk41kHqmMsP/34aLt7KdPUatg86fmhAu6Z1JpT6H9MPaVQ== 0 OK= ww4y/+3Ad05q/2rwhp9xqg868HqaManGhNsgfrDvjk41kHqmMsP/34aLt7KdPUatg86fmhAu6Z1JpT6H9MPaVQ== P'= oKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3w== 0
VB.NET
Console.WriteLine("Testing AES128_B64Mode ...") Dim nRet As Integer Dim strOutput As String Dim strInput As String Dim strKey As String Dim strIV As String ''Dim bEncrypt As Boolean Dim sCorrect As String ' Case #4: Encrypting 64 bytes (4 blocks) using AES-CBC with 128-bit key ' Key : 0x56e47a38c5598974bc46903dba290349 strKey = "VuR6OMVZiXS8RpA9uikDSQ==" ' IV : 0x8ce82eefbea0da3c44699ed7db51b7d9 strIV = "jOgu776g2jxEaZ7X21G32Q==" ' Plaintext : 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeaf ' b0b1b2b3b4b5b6b7b8b9babbbcbdbebf ' c0c1c2c3c4c5c6c7c8c9cacbcccdcecf ' d0d1d2d3d4d5d6d7d8d9dadbdcdddedf strInput = "oKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/" _ & "AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3w==" ' Ciphertext: 0xc30e32ffedc0774e6aff6af0869f71aa ' 0f3af07a9a31a9c684db207eb0ef8e4e ' 35907aa632c3ffdf868bb7b29d3d46ad ' 83ce9f9a102ee99d49a53e87f4c3da55 sCorrect = "ww4y/+3Ad05q/2rwhp9xqg868HqaManGhNsgfrDvjk" _ & "41kHqmMsP/34aLt7KdPUatg86fmhAu6Z1JpT6H9MPaVQ==" ' Set strOutput to be same length as strInput ''strOutput = String(Len(strInput), " ") Console.WriteLine("KY=" & strKey) Console.WriteLine("IV=" & strIV) Console.WriteLine("PT=" & strInput) strOutput = Aes128.Encrypt(strInput, strKey, Mode.CBC, strIV, EncodingBase.Base64) Console.WriteLine("CT=" & strOutput, nRet) Console.WriteLine("OK=" & sCorrect) strInput = strOutput strOutput = Aes128.Decrypt(strInput, strKey, Mode.CBC, strIV, EncodingBase.Base64) Console.WriteLine("P'=" & strOutput, nRet)
[Contents]