djvdberg Posted August 30, 2022 Share Posted August 30, 2022 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: 0o84agAykSYHoJnJuH1r7vOXVVoFEVq6vdIheMkHb+QDq2LuptbJQwrzUj+Vt73gJ3DiNvZ+B9SdgVfW8YNRMNkOEUdx5a3P9uqaZgocnGU= https://www.devglan.com/online-tools/aes-encryption-decryption 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? Thanks! Dion Link to comment Share on other sites More sharing options...
Developers Jos Posted August 30, 2022 Developers Share Posted August 30, 2022 Moved to the appropriate forum. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Solution TheXman Posted August 30, 2022 Solution Share Posted August 30, 2022 (edited) 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: Spoiler #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include <CryptoNG.au3> aes_cbc_encrypt_with_iv_example() 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) EndFunc Output 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 August 30, 2022 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
djvdberg Posted August 30, 2022 Author Share Posted August 30, 2022 Oh my goodness!! 2 weeks and you make it look so easy! Thanks again! Regards Dion Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now