www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Problem with digest Hmac sha256 method and another problem while

reply kerdemdemir <kerdemdemir gmail.com> writes:

I need to have the same result while using :

  openssl dgst -sha256 -hmac "somestring"

But the server rejecting my generated hmac with the code below .

auto hmac = HMAC!SHA256("somestring".representation);
auto generatedHmac = hmac.finish();
string generatedHmacStr = 

Saying generatedHmac is not correct.

Than I wanted to give a try with deimos-openssl like:

ubyte[32] hmac_sha256( string key, string data) {

        HMAC_CTX *ctx = new HMAC_CTX;

        auto digest = HMAC(EVP_sha256(),
                           cast(void *) key,
                           cast(int) key.length,
                           cast(ubyte*) data,
                           cast(int) data.length,
        ubyte[32] array = digest[0..32];
        return array;

But I am getting a linking error :

undefined reference to 

My dependencies in dub.json file is like:

     "dependencies": {
         "openssl": "~>1.1.6+1.0.1g",
         "vibe-d": "~>0.8.1",

I really want to solve linking error first. I tried installing 
openssl it didn't help. Any suggestions?

Dec 08 2017
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/08/2017 01:05 PM, kerdemdemir wrote:

 I need to have the same result while using :

Works for me as adapted from Phobos documentation: import std.stdio; import std.digest.hmac, std.digest.sha; import std.string : representation; void main() { auto hmac = HMAC!SHA256("key".representation); hmac.put("value".representation); foreach (m; hmac.finish()) { writef("%02x", m); } writeln(); } Assuming the program is called 'deneme', the result is the same: $ echo -n "value" | openssl dgst -sha256 -hmac "key" && ./deneme (stdin)= 90fbfcf15e74a36b89dbdb2a721d9aecffdfdddc5c83e27f7592594f71932481 90fbfcf15e74a36b89dbdb2a721d9aecffdfdddc5c83e27f7592594f71932481 Ali
Dec 08 2017