Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What is going on with this article?
@kou_pg_0131

【Node.js】文字列のハッシュ値を取得(SHA, MD5, RMD160)

More than 1 year has passed since last update.

関連

サンプルコード

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

参考

7
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kou_pg_0131
Goが好き

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
7
Help us understand the problem. What is going on with this article?