4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.jsで秘密鍵で署名して公開鍵で検証する

Posted at
var cryptor = require('crypto');
var sign = cryptor.createSign('RSA-SHA256');
sign.update('some data to sign');
var privateKey = fs.readFileSync(path.resolve('./signkey/secret.key'), "utf8");
var signedData = sign.sign(privateKey, 'base64');

var verify = cryptor.createVerify('RSA-SHA256');
verify.write('some data to sign');
verify.end();
var publicKey = fs.readFileSync(path.resolve('./signkey/public.key'), "utf8");
console.log(verify.verify(publicKey, signedData, 'base64'));

sign時とverify時でフォーマットをbase64ならbase64で合わせないと検証に失敗します。

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?