#1 2015-07-16 00:38:48

flyfire9
Member
Registered: 2015-07-16
Posts: 5

HELP: Why are there no encryption, decryption example? (AES)

hello everybody:
I need to use AES encryption, decryption, an example of a stream, who can give me a demo code ?
(Using TAESCBC )

Offline

#2 2015-07-16 11:18:37

alexdmatveev
Member
Registered: 2014-09-12
Posts: 87

Re: HELP: Why are there no encryption, decryption example? (AES)

var
  cryptedPassword, rawPassword: RawByteString;
  Key: TSHA256Digest;
begin
...
  rawPassword := password;
  SHA256Weak(MYSQL_PASSWORD_AESKEY, Key);
  cryptedPassword := SynCrypto.AES(Key, 256, rawPassword, true);
  password := BinToBase64(cryptedPassword);
...
end;

MYSQL_PASSWORD_AESKEY - string constrant containing aes key

Please try.
I hope it will be usefull.

Offline

#3 2015-07-16 13:31:19

flyfire9
Member
Registered: 2015-07-16
Posts: 5

Re: HELP: Why are there no encryption, decryption example? (AES)

thanks,
I need to encrypt and decrypt Tmemorystream, can you help me?

Offline

#4 2015-07-16 15:20:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: HELP: Why are there no encryption, decryption example? (AES)

Use TRawByteString as defined in SynCommons.pas: it inherits from TCustomMemoryStream, and would work directly from RawByteString variables.

Online

#5 2015-07-16 18:53:49

alexdmatveev
Member
Registered: 2014-09-12
Posts: 87

Re: HELP: Why are there no encryption, decryption example? (AES)

And pls keep in mind: SynCommons.pas and mORMot AES classes are not crossplatform.

Offline

#6 2015-07-16 21:53:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: HELP: Why are there no encryption, decryption example? (AES)

alexdmatveev wrote:

And pls keep in mind: SynCommons.pas and mORMot AES classes are not crossplatform.

.... Under Delphi.

But working on Linux (and also Darwin/MacOsX) with FPC.

Online

#7 2015-07-17 05:42:42

flyfire9
Member
Registered: 2015-07-16
Posts: 5

Re: HELP: Why are there no encryption, decryption example? (AES)

Thank you for your reply.

Sorry, I have not found TRawByteString , is it TSynMemoryStream ?
I would like to use "AES(CBC)", Is the use "TAESCBC" class ?
my code is :
....
clientdataset.SaveToStream(cds_st,dfBinary);
//encryption

Offline

#8 2015-07-17 05:56:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: HELP: Why are there no encryption, decryption example? (AES)

TRawByteStringStream class - sorry for the typo.
After a SaveToStream() on this class, use TAESCBC on the DataString method, then create a TRawByteStringStream instance from the encrypted RawByteString.

Online

#9 2015-07-17 08:57:23

flyfire9
Member
Registered: 2015-07-16
Posts: 5

Re: HELP: Why are there no encryption, decryption example? (AES)

Is there a method for : 
stream(in) -->stream (out encryption)  ?

Offline

#10 2015-07-17 09:12:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: HELP: Why are there no encryption, decryption example? (AES)

Not yet.

Online

#11 2015-07-17 13:02:50

flyfire9
Member
Registered: 2015-07-16
Posts: 5

Re: HELP: Why are there no encryption, decryption example? (AES)

Thank you very much.

Offline

Board footer

Powered by FluxBB