digitalmars.D.learn - Problem with digest Hmac sha256 method and another problem while
- kerdemdemir (35/35) Dec 08 2017 Hi,
- =?UTF-8?Q?Ali_=c3=87ehreli?= (18/21) Dec 08 2017 Works for me as adapted from Phobos documentation:
Hi,
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);
hmac.put(url.representation);
auto generatedHmac = hmac.finish();
string generatedHmacStr =
std.digest.digest.toHexString(generatedHmac);
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;
HMAC_CTX_init(ctx);
auto digest = HMAC(EVP_sha256(),
cast(void *) key,
cast(int) key.length,
cast(ubyte*) data,
cast(int) data.length,
null,null);
ubyte[32] array = digest[0..32];
return array;
}
But I am getting a linking error :
undefined reference to
`_D6deimos7openssl3evp13env_md_ctx_st6__initZ'
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?
Regards
Erdem
Dec 08 2017
On 12/08/2017 01:05 PM, kerdemdemir wrote:Hi, I need to have the same result while using : opensslWorks 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








=?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com>