-
Notifications
You must be signed in to change notification settings - Fork 374
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
QUESTION: use with webcrypto #61
Comments
I think you may want to do Thanks! |
many thanks for the reply, but key.verify() still returns false. if we are convinced that the any ideas? |
Aaah, I think you may want to try reverting the order of bytes in |
hi. maybe that's still an issue, but i'm still seeing
|
This one works: var createHash = require("crypto").createHash;
var EC = require("elliptic").ec;
var ec = new EC("p256");
var msg = Buffer("test");
var hash = createHash("sha256").update(msg).digest();
var alg = {name: "ECDSA", namedCurve: "P-256", hash: {name: "SHA-256"}};
function u8(a) { return new Uint8Array(a); }
crypto.subtle.generateKey(alg, true, ["sign"]).then(function(pair) {
crypto.subtle.exportKey("raw", pair.publicKey).then(function (publicKey) {
crypto.subtle.sign(alg, pair.privateKey, msg).then(function(sig) {
var r = sig.slice(0, 32);
var s = sig.slice(32);
console.log(ec.verify(hash, {r: u8(r), s: u8(s)}, u8(publicKey)));
});
});
}); |
many thanks. i am AFK right now, but will try this out ASAP! |
@Kagami this is very strange. May I ask you to provide me examples of hash, and sig? |
and publicKey for sure too. |
@brave-dev: in your samples you generate a P-256 (aka |
@dconnolly gosh, I totally missed it. You are right! |
👍 |
var createHash = require("crypto").createHash;
var EC = require("elliptic").ec;
var ec = new EC("p256");
var msg = Buffer("test");
var hash = createHash("sha256").update(msg).digest();
var alg = {name: "ECDSA", namedCurve: "P-256", hash: {name: "SHA-256"}};
function u8(a) { return new Uint8Array(a); }
crypto.subtle.generateKey(alg, true, ["sign"]).then(function(pair) {
crypto.subtle.exportKey("raw", pair.publicKey).then(function (publicKey) {
crypto.subtle.sign(alg, pair.privateKey, msg).then(function(sig) {
var r = sig.slice(0, 32);
var s = sig.slice(32);
console.log(ec.verify(hash, {r: u8(r), s: u8(s)}, u8(publicKey)));
console.log("HASH: " + hash.toString("hex"));
console.log("SIG: " + Buffer(sig).toString("hex"));
console.log("PKEY: " + Buffer(publicKey).toString("hex"));
});
});
});
|
@Kagami - thanks very much: that's a winner! |
let's say i'm using webcryptography in the browser and have some code like this:
what i am trying to figure out is how to take the two values in
payload
that contain hex-encoded strings and invoke key.verify() appropriately:can you advise me as to how i should be calling KeyFromPublic and verify?
thanks!
/mtr
cc: @diracdeltas
The text was updated successfully, but these errors were encountered: