Jump to content

Help with Rijndael/AES256 encryption - (Moved)

Go to solution Solved by TheXman,

Recommended Posts

Hallo all,

Please help, I have the following data:

  • String: lVc9ZKhCbxWaPdhIeMl3BJ16uF16F96jVoCj5LVyzWA=|creations0066|iJ+9E4x=*wM2c8_SZ%
  • IV: 79880A5F-D51C-43
  • Secret Key: 79880A5F-D51C-4336-9A7E-X1877CD6
  • Key Size: 256
  • Cypher Mode: CBC

If I use the below website, I get my expected outcome:



But, for the life of me, using CryptoNG I can't get the same??? Don't know if it's because it's binary,hex or ascii issues.

Can someone please point me in the right direction or provide some sample code?

Tried exampled from CryptoNG:

  • aes_cbc_encrypt_decrypt_with_iv_example()
  • pbkdf2_example()

I will happily post code but it's the examples I used to don't know if it will help much?



Link to comment
Share on other sites

  • Solution

The return value from _CryptoNG_AES_CBC_EncryptData() is a binary string, not a Base64 string.  Your expected result is a Base64 string.  On the site that you referenced, you can choose to have the result output in HEX or Base64.  If you choose HEX and if your CryptoNG example script is successful, then you should see the same HEX (BINARY) result.  If you want a Base64 result, then you just need to convert the binary result to a Base64 string.  You can do that using _CryptoNG_CryptBinaryToString().

See example below:

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <CryptoNG.au3>


Func aes_cbc_encrypt_with_iv_example()

    Const $ALG_ID      = "AES CBC"
    Const $PLAIN_TEXT  = "lVc9ZKhCbxWaPdhIeMl3BJ16uF16F96jVoCj5LVyzWA=|creations0066|iJ+9E4x=*wM2c8_SZ%"
    Const $KEY         = "79880A5F-D51C-4336-9A7E-X1877CD6"
    Const $IV          = "79880A5F-D51C-43"

    Local $xEncryptedMessage = Binary("")
    Local $sBase64String     = ""

    ;Encrypt message
    $xEncryptedMessage = _CryptoNG_AES_CBC_EncryptData($PLAIN_TEXT, $KEY, $IV)
    If @error Then Exit ConsoleWrite("EncryptData Error: " & _CryptoNG_LastErrorMessage() & @CRLF)

    ;Convert binary result to base64 string
    $sBase64String = _CryptoNG_CryptBinaryToString($xEncryptedMessage, $CNG_CRYPT_STRING_BASE64 + $CNG_CRYPT_STRING_NOCRLF)
    If @error Then Exit ConsoleWrite("BinaryToString Error: " & _CryptoNG_LastErrorMessage() & @CRLF)

    ;Display results
    ConsoleWrite(StringFormat("%s Plain text message          = %s", $ALG_ID, $PLAIN_TEXT) & @CRLF)
    ConsoleWrite(StringFormat("%s Encryption Key              = %s", $ALG_ID, $KEY) & @CRLF)
    ConsoleWrite(StringFormat("%s Initialization Vector       = %s", $ALG_ID, $IV) & @CRLF)
    ConsoleWrite(StringFormat("%s Encrypted Message (BINARY)  = %s", $ALG_ID, $xEncryptedMessage) & @CRLF)
    ConsoleWrite(StringFormat("%s Encrypted Message (BASE64)  = %s", $ALG_ID, $sBase64String) & @CRLF)



AES CBC Plain text message          = lVc9ZKhCbxWaPdhIeMl3BJ16uF16F96jVoCj5LVyzWA=|creations0066|iJ+9E4x=*wM2c8_SZ%
AES CBC Encryption Key              = 79880A5F-D51C-4336-9A7E-X1877CD6
AES CBC Initialization Vector       = 79880A5F-D51C-43
AES CBC Encrypted Message (BINARY)  = 0xD28F386A0032912607A099C9B87D6BEEF397555A05115ABABDD22178C9076FE403AB62EEA6D6C9430AF3523F95B7BDE02770E236F67E07D49D8157D6F1835130D90E114771E5ADCFF6EA9A660A1C9C65
AES CBC Encrypted Message (BASE64)  = 0o84agAykSYHoJnJuH1r7vOXVVoFEVq6vdIheMkHb+QDq2LuptbJQwrzUj+Vt73gJ3DiNvZ+B9SdgVfW8YNRMNkOEUdx5a3P9uqaZgocnGU=



Edited by TheXman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...