how to print ubyte*

2014-04-30 Thread brad clawsie via Digitalmars-d-learn

hi, I'm back again with another openssl related question.

given this program

--

  import std.stdio;
  import deimos.openssl.hmac;
  import deimos.openssl.evp;

  void main() {
  HMAC_CTX *ctx = new HMAC_CTX;
  HMAC_CTX_init(ctx);
  auto key = 123456;
  auto s = hello;

  auto digest = HMAC(EVP_sha1(),
 cast(void *) key,
 cast(int) key.length,
 cast(ubyte*) s,
 cast(int) s.length,
 null,null);
  }

--

digest should be of type ubyte*

does anyone know how to print this out as ascii?

thanks!
brad


AES encryption with openssl bindings

2014-04-25 Thread brad clawsie via Digitalmars-d-learn

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