Thread overview
SHA256 Signature
Jun 18
Vahid
Jun 18
Erdem
Jun 18
Vahid
June 18

Hi,

How can I create a SHA256 signature hash in D? Something similar to the PHP code below:

openssl_sign($body, $signature, $secret, OPENSSL_ALGO_SHA256);

I've tried the code below without success:

auto signature = body.representation.hmac!SHA256(secret.representation).toHexString!(LetterCase.lower).to!string;
June 18

On Tuesday, 18 June 2024 at 06:49:24 UTC, Vahid wrote:

>

How can I create a SHA256 signature hash in D?

Does this do what you want?

import std.digest.md;
import std.digest.sha;
import std.stdio;

void main()
{
    auto key = makeDigest!SHA256();
    key.put(cast(ubyte[])"çorba");
    auto result = key.finish();
    writeln(result.toHexString());
}
June 18

On Tuesday, 18 June 2024 at 17:18:18 UTC, Erdem wrote:

>

On Tuesday, 18 June 2024 at 06:49:24 UTC, Vahid wrote:

>

How can I create a SHA256 signature hash in D?

Does this do what you want?

import std.digest.md;
import std.digest.sha;
import std.stdio;

void main()
{
    auto key = makeDigest!SHA256();
    key.put(cast(ubyte[])"çorba");
    auto result = key.finish();
    writeln(result.toHexString());
}

Thank you for your reply.

I have found that the issue is related to the 'Secret' variable. In fact, I possess a private key that needs to sign it for the JWT. How can I accomplish this? It appears that RSA encryption is required in this scenario.