AES encryption with openssl bindings
Justin Whear via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 25 13:13:15 PDT 2014
On Fri, 25 Apr 2014 19:06:31 +0000, brad clawsie wrote:
> hi everyone.
>
> I'm trying to symmetrically encrypt some text using the openssl
> bindings. My code compiles and fails silently. Clearly there is
> something very wrong with it - it could be my novice D skills, or my
> misuse of the openssl binding.
>
> auto chunk = new ubyte[](16);
> foreach(ref x; chunk) x = uniform!"[]"(ubyte.min, ubyte.max);
> AES_KEY wctx;
> AES_set_encrypt_key(chunk.ptr,128,&wctx);
>
> string s = "virident";
> ubyte[] b;
> b = cast(ubyte[]) s;
> ubyte[] e;
> AES_encrypt(b.ptr,e.ptr,&wctx);
> ubyte[] d;
> AES_decrypt(e.ptr,d.ptr,&wctx);
> writefln("%s",d);
>
>
> Any clues? I am a D novice, so any spoonfeeding you could provide would
> be helpful :)
>
> thanks!
> Brad
It doesn't look like you're allocating space for `e` or `d`, e.g. `auto e
= new ubyte[](256);`, so those arrays have a length of 0, in which case
the encrypt/decrypt functions are just trashing their way through memory.
More information about the Digitalmars-d-learn
mailing list