15
7

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】文字列のハッシュ値を取得(SHA, MD5, RMD160)

Last updated at Posted at 2019-09-15

関連

サンプルコード

const crypto = require('crypto');

const plainText = 'password';

// サポートされているハッシュアルゴリズムを確認
console.log(crypto.getHashes());
// => [ 'RSA-MD4',
//      'RSA-MD5',
//      'RSA-MDC2',
//      'RSA-RIPEMD160', ...

// `crypto.createHash('アルゴリズム名').update('文字列').digest('hex')`
console.log('md5:    ' + crypto.createHash('md5').update(plainText).digest('hex'));
console.log('rmd160: ' + crypto.createHash('rmd160').update(plainText).digest('hex'));
console.log('sha1:   ' + crypto.createHash('sha1').update(plainText).digest('hex'));
console.log('sha256: ' + crypto.createHash('sha256').update(plainText).digest('hex'));
console.log('sha384: ' + crypto.createHash('sha384').update(plainText).digest('hex'));
console.log('sha512: ' + crypto.createHash('sha512').update(plainText).digest('hex'));

// => md5:    5f4dcc3b5aa765d61d8327deb882cf99
//    rmd160: 2c08e8f5884750a7b99f6f2f342fc638db25ff31
//    sha1:   5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
//    sha256: 5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
//    sha384: a8b64babd0aca91a59bdbb7761b421d4f2bb38280d3a75ba0f21f2bebc45583d446c598660c94ce680c47d19c30783a7
//    sha512: b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86

参考

15
7
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
15
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?