nodejs之bcrypt

2020-03-21  本文已影响0人  简爱WindMan

安装

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使用

// 获取密钥
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');
    });
  });
})
上一篇 下一篇

猜你喜欢

热点阅读