74

誰かが2つの状況とそれぞれを使用する例の状況の違いを指摘できますか?

bcryptは素晴らしく見えます。

4

5 に答える 5

95

低速で計算コストの高いハッシュを行いたい場合は bcrypt を使用します。これは通常、ユーザー パスワードなど、攻撃者にハッシュを元に戻してほしくない場合に使用します。他のすべてにはネイティブ暗号を使用します。

于 2011-08-05T05:43:48.173 に答える
25

@mike-scott の回答と併せて、bcryptパスワード関連のものを優先する必要がありますがcrypto、ランダム トークンや HMAC チェックサム、SHA1/MD5 ハッシュの作成など、幅広いタスクに使用できます。

var crypto = require('crypto'); 

// random tokens
var buf = crypto.randomBytes(16).toString('hex');
console.log('Random token of %d bytes in hexadecimal: %s', buf.length, buf);
var buf = crypto.randomBytes(16).toString('base64');
console.log('Random token of %d bytes in base 64: %s', buf.length, buf);

// a hashed message authentication checksum (HMAC) using a shared secret key
var string = 'My coffee please';
var key = 'Right away sir';

var encrypted = crypto.createHmac('sha1', key).update(string).digest('hex');
console.log('Encrypting "%s" using passphrase "%s": %s', string, key, encrypted);

// a MD5 hash
var hashmd5 = crypto.createHash('md5').update(string).digest('hex');
console.log('The MD5 hash of "%s" is %s', string, hashmd5); 

// a SHA1 hash
var hashsha1 = crypto.createHash('sha1').update(string).digest('hex');
console.log('The SHA1 hash of "%s" is %s', string, hashsha1); 
于 2014-04-26T20:26:45.407 に答える