Re: Symmetric encryption sample code
"H. William Welliver III" <[email protected]> Tue, 30 Apr 2019 20:27:29 -0400
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <[email protected]> |
So, you are seeing that cryptography is hard… it’s not as simple as saying, “decrypt this using AES”. There are a fairly large number of parameters that you’d need to specify and most tools aren’t that flexible. A solution for you might involve providing a decryption program configured using the same parameters that you use to encrypt.
It’s hard to know what the problem here is, as the source isn’t available. There are a number of things that can affect whether encryption and decryption will work: how the key is specified (we provide it as a series of n bytes, but a lot of tools assume a key is an ascii string and expand it to the correct number of bytes), etc.
I was able to get the encrypted result from [1] to work with the example decryptor I sent. I was /unable/ to get the encrypted output to work with the same tool regardless of whether I used ECB or CBC, with an error of “final block not properly padded”. I am assuming that the Buffer pads according to either ISO 10126 or the like; it’s unclear what the various online decryptors expect.
Perhaps there’s something in the Crypto.PGP support that could be a short-cut for you?
Bill
[1] https://www.devglan.com/online-tools/aes-encryption-decryption
>> 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 <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
>
>
>