Node.js/crypto:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第176行: 第176行:
console.log(decrypted);</syntaxhighlight>|{{consoleout|<pre>
console.log(decrypted);</syntaxhighlight>|{{consoleout|<pre>
i l y
i l y
</pre>}}}}
使用流。
{{leftrightflex|<syntaxhighlight lang="javascript">
const crypto = require('crypto');
const salt = 'lanqian';
const pubkey = 'kangkk';
const key = crypto.scryptSync(pubkey, salt, 24);
const cipher = crypto.createCipheriv('aes192', key, Buffer.alloc(16, 0));
const data = 'i l y';
let encryted = '';
cipher.on('readable', () => {
  let chunk;
  while (null !== (chunk = cipher.read())) {
      encryted += chunk.toString('utf8');
  }
});
cipher.on('end', () => {
  console.log(encryted);
});
cipher.write(data, 'utf8');
cipher.end();</syntaxhighlight>|{{consoleout|<pre>
�T<�NT��|�꣣�
</pre>}}}}
</pre>}}}}