Re: Symmetric encryption sample code

"Bertrand LUPART - Linkeo.com" <[email protected]> Tue, 30 Apr 2019 23:57:40 +0200
Newsgroups gmane.comp.lang.pike.user
Message-ID <[email protected]>
Hello Bill,


> 7.6? That's a classic vintage!

Yeah, some quite venerable Caudium boxen :)


> Here's some code to get you started... I'm sure that the crypto experts will be able to provide additional detail.
> 
>> object b = Crypto.Buffer(Crypto.AES);
>> b->set_encrypt_key("b" * 16); // AES keys may be 128, 192 or 256 bits.
>> string e = b->crypt("Mary had a little pike, its scales were smooth and 
> shiny.");
>> e+=b->pad(); // pad out the AES block.
> // E contains a binary string. You may wish to encode this (base 64, hex, etc) for easier transfer
> 
> // Decrypt E
>> object b = Crypto.Buffer(Crypto.AES);
>> b->set_decrypt_key("b" * 16);
>> b->unpad(e);
> Result: "Mary had a little pike, its scales were smooth and shiny."

Looks good, thank you for your answer.


However, i should ensure the data can be deciphered on the other side using unknown tech, and i can't manage to get the same results than this page :

https://aesencryption.net
"Mary had a little pike, its scales were smooth and shiny."
"bbbbbbbbbbbbbbbb"
128 bits
Base64 result : "TVwyvflyoe2wLb2FmV1qmm1err+Knp+2ArGNh2N/A3coFId2CvqIkxMb4pw7c6E+Wxd3VOoHscAXnGTDPE/R3w=="



The Pike code : 

> object b = Crypto.Buffer(Crypto.AES);                                            
> b->set_encrypt_key("b" * 16);                                                    
(1) Result: 0
> string e = b->crypt("Mary had a little pike, its scales were smooth and shiny.");
> e+=b->pad();                                                                     
(2) Result: "\371\36\331\240\4\202\225""5/[\215\375z@\323C:u\bX\362@\352p\357lb\36G\201\377\27""2\224\234\306\253\220\t\204\266\340\372\23F\f\255""2vX\b\375H\f\317z\0\273""2\254\370""9\206\257"
> MIME.encode_base64(e,1);                                                         
(3) Result: "+R7ZoASClTUvW439ekDTQzp1CFjyQOpw72xiHkeB/xcylJzGq5AJhLbg+hNGDK0ydlgI/UgMz3oAuzKs+DmGrw=="
> MIME.encode_base64(String.string2hex(e),1);                                      
(4) Result: "ZjkxZWQ5YTAwNDgyOTUzNTJmNWI4ZGZkN2E0MGQzNDMzYTc1MDg1OGYyNDBlYTcwZWY2YzYyMWU0NzgxZmYxNzMyOTQ5Y2M2YWI5MDA5ODRiNmUwZmExMzQ2MGNhZDMyNzY1ODA4ZmQ0ODBjY2Y3YTAwYmIzMmFjZjgzOTg2YWY="
> MIME.encode_base64(String.hex2string(e),1);                                      
(5) Result: "7ilL5fRmOcw+gbk5hf4K5y1fSZ358/xi8YbcgwQlGfg="


-- 
Bertrand LUPART
smime.p7s (application/pkcs7-signature, 3.8 KB) - not displayed