Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to format a PHP-OpenSSL signature to be verifiable with elliptic? #293

Open
gitgoodboy opened this issue Nov 22, 2022 · 1 comment
Open

Comments

@gitgoodboy
Copy link

How to verify something like this?

PHP

$privkey = "-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIElP6IpLbE3Jd7KdBjlHtgtJfcZ94/OEkCoIsl/iV8q8oAcGBSuBBAAK
oUQDQgAECQ5QVzipmVe7SUco3rzOgvaO+f70wN5jVVHDK2bSVY1OV3OCW0UZmSjU
az/p1DNMYv9tcjPUuPwf+eCtxXSepg==
-----END EC PRIVATE KEY-----
";

openssl_sign(bin2hex($data), $sign, $privkey, OPENSSL_ALGO_SHA256);
$sign = base64_encode($sign);

This always returns false:

Typescript

const data: string = json_response["data"];
const sign64: string = json_response["sign64"];

let EC = require('elliptic').ec;
let ec = new EC('secp256k1');
let key = ec.keyFromPublic("04090e505738a99957bb494728debcce82f68ef9fef4c0de635551c32b66d2558d4e5773825b45199928d46b3fe9d4334c62ff6d7233d4b8fc1ff9e0adc5749ea6", 'hex');

let sign = Buffer.from(sign64, "base64").toString("hex");
let datahex = Buffer.from(data, "utf-8").toString("hex");

console.log(key.verify(datahex, sign));
Red-Bowler added a commit to Red-Bowler/elliptic that referenced this issue Nov 24, 2022
Added note to clarify signed data must be hashed before signature or verification process in response to issue indutny#293 .
@Red-Bowler
Copy link

I suggested a change to REAME.md.
You must hash your data manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants