How to hash SHA256 from string?

user1234 user1234 at 12.de
Sat Dec 2 16:19:14 UTC 2023


On Saturday, 2 December 2023 at 16:17:08 UTC, user1234 wrote:
> On Saturday, 2 December 2023 at 15:30:39 UTC, zoujiaqing wrote:
>> [...]
>
> sign is binary, you have to use the toHexString utility :
>
> ```d
> import std.stdio;
> import std.digest.sha;
>
> void main()
> {
>
>     SHA256 sha256;
>     sha256.start();
>     string appKey = 
> "11111111111111111111111111111111111111111111111111111";
>     sha256.put(cast(ubyte[])appKey);
>     ubyte[32] sign = sha256.finish();
>     writeln("sign: %s", toHexString(sign));
> }
> ```
>
> also you add a range error on data assignment.

and a last error I have not initially catch, use writefln:

```d
writefln("sign: %s", toHexString(sign));
```


More information about the Digitalmars-d-learn mailing list