Sowmya Posted September 4, 2024 Posted September 4, 2024 I am trying to encrypt data in java using AES GCM and decrypt same in autoit, however decryption fails in autoit. Even i am facing issue with encryption in autoit as well: Local $sAlgorithmId = "RNG" Local $tKey = _CryptoNG_GenerateRandom($sAlgorithmId, 32) ; 32 bytes = 256 bits Local $tNonce = _CryptoNG_GenerateRandom($sAlgorithmId, 12) ; 12 bytes nonce ; Check if key and nonce were generated correctly If @error Then MsgBox(16, "Error", "Failed to generate random key or nonce. Error: " & @error) _Crypt_Shutdown() Exit EndIf ; Define the plaintext to encrypt Local $sPlainText = "This is a secret message." ; Convert the plaintext to binary for encryption Local $tPlainTextBin = StringToBinary($sPlainText) ; Default to UTF-16LE encoding ; Check if conversion was successful If @error Then MsgBox(16, "Error", "Failed to convert plaintext to binary. Error: " & @error) _Crypt_Shutdown() Exit EndIf ; Encrypt the plaintext using AES-GCM Local $tEncryptedData = _CryptoNG_AES_GCM_EncryptData($tPlainTextBin, $tKey, $tNonce, 128) And decryption: Local $tDecryptedData = _CryptoNG_AES_GCM_DecryptData($tEncryptedData, $tKey, $tNonce, 128) what should be the format of tEncryptedData? Whether $tKey and $tNonce should be in hex format or binary.
Sowmya Posted September 4, 2024 Author Posted September 4, 2024 And i am using cryptong.au3 for encryption and decryption.
TheXman Posted September 4, 2024 Posted September 4, 2024 (edited) Did you use ChatGPT to generate your example script? It has multiple issues and obviously will not run as written. No one who has spent any time looking at the CryptoNG help file and/or looking over the numerous examples that were provided with the UDF would have used _Crypt_Shutdown() in a CryptoNG script. That function is from a totally different UDF (crypt.au3). Why didn't you use the AES GCM example that comes with the CryptoNG UDF as a guide? Edited September 5, 2024 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
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