Jump to content

Encryption and Decryption using _CryptoNG_AES_GCM_EncryptData and _CryptoNG_AES_GCM_DecryptData


Recommended Posts

Posted

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.

Posted (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 by TheXman

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
×
×
  • Create New...