Last active
January 23, 2025 13:24
Mormot Crypt Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit uCrypt; | |
interface | |
uses | |
Winapi.Windows, | |
Winapi.Messages, | |
System.SysUtils, | |
System.Variants, | |
System.Classes, | |
Vcl.Controls, | |
Vcl.Forms, | |
Vcl.Dialogs, | |
Vcl.StdCtrls, | |
System.NetEncoding, | |
mormot.crypt.core, | |
mormot.crypt.secure, | |
mormot.core.text; | |
type | |
TMyCryptAndHash = class | |
private | |
public | |
function AESEncrypt(PlainText: string; Akey: RawByteString): string; | |
end; | |
implementation | |
function TMyCryptAndHash.AESEncrypt(PlainText: string; AKey: RawByteString): string; | |
var | |
Lkey : RawByteString; | |
CryptCipher: ICryptCipher; | |
dest: TBytes; | |
Bytes: TBytes; | |
begin | |
Lkey := HexToBin(SHA256(AKey)); | |
Bytes := TEncoding.UTF8.GetBytes(PlainText); | |
CryptCipher := Encrypt('aes-256-gcm', Pointer(Lkey)); //nil | |
CryptCipher.Process(Bytes, dest, nil); // access violation here , value is nil | |
Result := TNetEncoding.Base64.EncodeBytesToString(dest); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment