You are not logged in.
Pages: 1
Encrypted string does not decrypt with AESDecrypt with error: TAesGcm.DecryptPkcs7: Invalid Input.
function AESEncrypt2(PlainText: string; Key: RawByteString): string;
var
akey : RawByteString;
CryptCipher: ICryptCipher;
dest,Bytes: TBytes;
begin
akey := HexToBin(SHA256(Key));
Bytes := TEncoding.UTF8.GetBytes(PlainText);
CryptCipher := Encrypt('aes-256-gcm', Pointer(akey));
CryptCipher.Process(Bytes, dest, nil);
Result := TNetEncoding.Base64.EncodeBytesToString(dest);
end;
function AESDecrypt(CipherText: string; Key: RawByteString): string;
var
AES: mormot.crypt.core.TAesGcm;
akey : RawByteString;
begin
akey := HexToBin(SHA256(Key));
AES := mormot.crypt.core.TAesGcm.Create(pointer(akey)^, 256);
try
Result := AES.DecryptPkcs7(Base64ToBin(CipherText), False);
finally
AES.Free;
end;
end;
Last edited by anouri (2025-01-09 12:30:13)
Offline
You need to follow TCryptAesCipher.Process() encoding, i.e. standard GCM algorithm with trailing 128-bit GMAC.
Your AESDecrypt() does not follow this encoding.
Why are you mixing APIs?
Use ICryptCipher on both sides.
Offline
I had used TAes for Aes Gcm before, you suggested I use ICryptCipher. I tried using the suggested method.
But I wanted to see if the string encrypted with the first method can be decrypted with high level ICryptCipher. My attempt was unsuccessful.
Last edited by anouri (2025-01-09 16:27:11)
Offline
TCryptAesCipher in mormot.crypt.secure is not visible?!
I can't use it
Offline
After couple of days I can't figure out right way to encrypt AES GCM.
Even AIs don't give the right answer. I can't find any educational resources on YouTube or anywhere else.
Offline
What is wrong with
- Encrypt('aes-256-gcm', pointer(key)).Process()
- Decrypt('aes-256-gcm', pointer(key)).Process()
What do you want to achieve exactly?
Forget about AI they are far too limited to understand pascal.
Offline
I just wanted to make sure that what I was doing was correct and that I had done a standard and proper encryption. And I needed your confirmation.
Which seemed to be correct. Thank you.
Offline
Pages: 1