www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - jsnode crypto createHmac & createHash

reply "andre" <andre s-e-a-p.de> writes:
Hi,

I translate some functionality written in jsnode,
which contains a crypto library.

Although there is some sha256 support in
phobos I think, they do not provide all functionality
I need to translate following two functions.
(Input and output is ubyte[])

Is there a library which supports the methods
similiar (createHmac, update)... ?

function hmac(key, msg) {
   var hash = crypto.createHmac('sha256', key);
   hash.update(msg);
   return new Buffer(hash.digest(), 'binary');
}

function sha256(msg) {
   var hash = crypto.createHash('sha256');
   hash.update(msg);
   return new Buffer(hash.digest(), 'binary');
}

Kind regards
André
Nov 28 2014
next sibling parent reply Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn writes:
V Fri, 28 Nov 2014 12:46:25 +0000
andre via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
napsáno:

 Hi,
 
 I translate some functionality written in jsnode,
 which contains a crypto library.
 
 Although there is some sha256 support in
 phobos I think, they do not provide all functionality
 I need to translate following two functions.
 (Input and output is ubyte[])
 
 Is there a library which supports the methods
 similiar (createHmac, update)... ?
 
 function hmac(key, msg) {
    var hash = crypto.createHmac('sha256', key);
    hash.update(msg);
    return new Buffer(hash.digest(), 'binary');
 }
 
 function sha256(msg) {
    var hash = crypto.createHash('sha256');
    hash.update(msg);
    return new Buffer(hash.digest(), 'binary');
 }
 
 Kind regards
 André
I am using https://github.com/pszturmaj/phobos/tree/master/std/crypto
Nov 28 2014
parent "andre" <andre s-e-a-p.de> writes:
fantastic, thanks a lot.

Kind regards
André

On Friday, 28 November 2014 at 13:09:34 UTC, Daniel Kozák via
Digitalmars-d-learn wrote:
 V Fri, 28 Nov 2014 12:46:25 +0000
 andre via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com>
 napsáno:

 Hi,
 
 I translate some functionality written in jsnode,
 which contains a crypto library.
 
 Although there is some sha256 support in
 phobos I think, they do not provide all functionality
 I need to translate following two functions.
 (Input and output is ubyte[])
 
 Is there a library which supports the methods
 similiar (createHmac, update)... ?
 
 function hmac(key, msg) {
    var hash = crypto.createHmac('sha256', key);
    hash.update(msg);
    return new Buffer(hash.digest(), 'binary');
 }
 
 function sha256(msg) {
    var hash = crypto.createHash('sha256');
    hash.update(msg);
    return new Buffer(hash.digest(), 'binary');
 }
 
 Kind regards
 André
I am using https://github.com/pszturmaj/phobos/tree/master/std/crypto
Nov 28 2014
prev sibling parent Etienne Cimon <etcimon gmail.com> writes:
Keep an eye on this one: Botan in D, https://github.com/etcimon/botan

Should be finished in a couple weeks.

e.g. from the TLS module:

auto hmac = get_mac("HMAC(SHA-256)");
hmac.set_key(secret_key);
hmac.update_be(client_hello_bits.length);
hmac.update(client_hello_bits);
hmac.update_be(client_identity.length);
hmac.update(client_identity);
m_cookie = unlock(hmac.flush());
Nov 28 2014