Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
July 18, 2018 HMAC and toHexString | ||||
---|---|---|---|---|
| ||||
... string key = "blahblahblah"; auto mac = hmac!SHA256(key.representation); string s = ...,t=...u=...,v=...; foreach(w;AliasSeq!(s,t,u,v)) mac.put(w.representation); ubyte[32] s = mac.finish; string sig = toHexString!(LetterCase.lower)(s); writeln(sig); // From what I understand Should print something like 41771e2d0d6c1cf7f442aa8547783ea5b126bfc15a4b354e94d0eaea2ab0fa1a // Actually prints something like x"31 36 39 33 39 32 38 31 62 38 31 62 36 36 62 63 63 34 63 36 36 61 62 32 34 37 64 32 64 34 61 00 78 2A 55 5B FF 7F 00 00 78 2A 55 5B FF 7F 00 00 E0 2A 55 5B FF 7F 00 00 08 2C 55 5B FF 7F 00 00"c Note the nuls and things like FF What am I doing wrong here? |
July 18, 2018 Re: HMAC and toHexString | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Wednesday, 18 July 2018 at 05:54:48 UTC, Nicholas Wilson wrote: > ... > string key = "blahblahblah"; > auto mac = hmac!SHA256(key.representation); > string s = ...,t=...u=...,v=...; > foreach(w;AliasSeq!(s,t,u,v)) > mac.put(w.representation); > ubyte[32] s = mac.finish; > string sig = toHexString!(LetterCase.lower)(s); > > writeln(sig); > // From what I understand Should print something like 41771e2d0d6c1cf7f442aa8547783ea5b126bfc15a4b354e94d0eaea2ab0fa1a > // Actually prints something like x"31 36 39 33 39 32 38 31 62 38 31 62 36 36 62 63 63 34 63 36 36 61 62 32 34 37 64 32 64 34 61 00 78 2A 55 5B FF 7F 00 00 78 2A 55 5B FF 7F 00 00 E0 2A 55 5B FF 7F 00 00 08 2C 55 5B FF 7F 00 00"c > Note the nuls and things like FF > > What am I doing wrong here? Don't know, what you mean. Works for me: ´´´ import std.stdio; import std.digest.hmac; import std.digest.sha; import std.string; import std.meta; void main() { string key = "blahblahblah"; auto mac = hmac!SHA256(key.representation); string s = "...",t="...", u="...",v="..."; foreach(w;AliasSeq!(s,t,u,v)) mac.put(w.representation); ubyte[32] r = mac.finish; r.toHexString!(LetterCase.lower).writeln; } ´´´ output: dc84632fc9b5d1f4b879d9aa021ae0d089e7f66a2fd2e824829cfceedbece729 |
July 18, 2018 Re: HMAC and toHexString | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Wednesday, 18 July 2018 at 05:54:48 UTC, Nicholas Wilson wrote:
> ...
> string key = "blahblahblah";
> auto mac = hmac!SHA256(key.representation);
> string s = ...,t=...u=...,v=...;
> foreach(w;AliasSeq!(s,t,u,v))
> mac.put(w.representation);
> ubyte[32] s = mac.finish;
> string sig = toHexString!(LetterCase.lower)(s);
>
> writeln(sig);
> // From what I understand Should print something like 41771e2d0d6c1cf7f442aa8547783ea5b126bfc15a4b354e94d0eaea2ab0fa1a
> // Actually prints something like x"31 36 39 33 39 32 38 31 62 38 31 62 36 36 62 63 63 34 63 36 36 61 62 32 34 37 64 32 64 34 61 00 78 2A 55 5B FF 7F 00 00 78 2A 55 5B FF 7F 00 00 E0 2A 55 5B FF 7F 00 00 08 2C 55 5B FF 7F 00 00"c
> Note the nuls and things like FF
>
> What am I doing wrong here?
Ahh, the joys of memory corruption.
|
July 18, 2018 Re: HMAC and toHexString | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Wednesday, 18 July 2018 at 11:22:36 UTC, Nicholas Wilson wrote: > On Wednesday, 18 July 2018 at 05:54:48 UTC, Nicholas Wilson wrote: >> [...] > > Ahh, the joys of memory corruption. You've reached https://issues.dlang.org/show_bug.cgi?id=16519 maybe ? |
July 18, 2018 Re: HMAC and toHexString | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On Wednesday, 18 July 2018 at 11:22:36 UTC, Nicholas Wilson wrote:
> On Wednesday, 18 July 2018 at 05:54:48 UTC, Nicholas Wilson wrote:
>> [...]
>
> Ahh, the joys of memory corruption.
Yep, actually this one is a very common one.
However, -dip1000 would warn you here ...
|
July 18, 2018 Re: HMAC and toHexString | ||||
---|---|---|---|---|
| ||||
Posted in reply to baz@dlang-community | On Wednesday, 18 July 2018 at 11:29:42 UTC, baz@dlang-community wrote:
> On Wednesday, 18 July 2018 at 11:22:36 UTC, Nicholas Wilson wrote:
>> On Wednesday, 18 July 2018 at 05:54:48 UTC, Nicholas Wilson wrote:
>>> [...]
>>
>> Ahh, the joys of memory corruption.
>
> You've reached https://issues.dlang.org/show_bug.cgi?id=16519 maybe ?
Not sure if it was that or some of the other memory corruption I was experiencing.
|
Copyright © 1999-2021 by the D Language Foundation