安裝
- 不值為何妨马,node_modules/bcrypt/examples/forever_gen_salt.js 其他版本一直報錯寺庄,只有3.0.0版本可用,如下
node forever_gen_salt.js
dyld: lazy symbol binding failed: Symbol not found: __ZN4node19GetCurrentEventLoopEPN2v87IsolateE
Referenced from: /xxxx/wmNode/node_modules/bcrypt/lib/binding/bcrypt_lib.node
Expected in: flat namespace
dyld: Symbol not found: __ZN4node19GetCurrentEventLoopEPN2v87IsolateE
Referenced from: /Users/developer/Desktop/Life/MyCode/wmNode/node_modules/bcrypt/lib/binding/bcrypt_lib.node
Expected in: flat namespace
Abort trap: 6
- bcrypt文檔介紹,安裝需要node的穩(wěn)定版本;
- 用nvm切換到node的10.0版本您旁,即可安裝
bcrypt使用
// 獲取密鑰
bcrypt.genSalt(10, function(err, salt) {
console.log('salt: ' + salt);
console.log('salt cb end: ' + (Date.now() - start) + 'ms');
// 用密鑰salt,加密字符串test
bcrypt.hash('test', salt, function(err, crypted) {
console.log('crypted: ' + crypted);
console.log('crypted cb end: ' + (Date.now() - start) + 'ms');
console.log('rounds used from hash:', bcrypt.getRounds(crypted));
// 比較轴捎,成功
bcrypt.compare('test', crypted, function(err, res) {
console.log('compared true: ' + res);
console.log('compared true cb end: ' + (Date.now() - start) + 'ms');
});
// 比較鹤盒,失敗
bcrypt.compare('bacon', crypted, function(err, res) {
console.log('compared false: ' + res);
console.log('compared false cb end: ' + (Date.now() - start) + 'ms');
});
});
})