仕事に行けないcrypto
。
- ウィンドウズ7 64ビット
- node.js v0.10.18
暗号化は機能しているようです:
var fs = require('fs');
var img = new Buffer (fs.readFileSync('./image.png'), 'binary');
var crypto = require('crypto')
, key = 'salt_from_the_user_document'
, plaintext = img
, cipher = crypto.createCipher('aes-256-cbc', key)
, decipher = crypto.createDecipher('aes-256-cbc', key);
cipher.update(plaintext, 'binary', 'base64');
var encryptBinary = cipher.final('base64')
console.log('encrypted :', encryptBinary);
...しかし、復号化はできません。
decipher.update(encryptBinary, 'base64', 'binary');
var decryptBinary = decipher.final('binary');
console.log('decrypted :', decryptBinary);
node-efsと同じ復号化の問題。
var efs = require('efs').init('aes-128-cbc', 'password');
// encrypt and write file
efs.writeFileSync('/tmp/example', 'hello world');
// decrypt and read file
efs.readFileSync('/tmp/example');
file-encryptorと同じ問題。
これは機能します(文字列のみ):
var crypto = require('crypto')
, key = 'salt_from_the_user_document'
, plaintext = 'password'
, cipher = crypto.createCipher('aes-256-cbc', key)
, decipher = crypto.createDecipher('aes-256-cbc', key);
cipher.update(plaintext, 'utf8', 'base64');
var encryptedPassword = cipher.final('base64')
decipher.update(encryptedPassword, 'base64', 'utf8');
var decryptedPassword = decipher.final('utf8');
console.log('encrypted :', encryptedPassword);
console.log('decrypted :', decryptedPassword);