LoginSignup
9
6

More than 3 years have passed since last update.

NodeJS で AESなどで暗号化する方法メモ

Last updated at Posted at 2015-12-17

こんな感じのプログラムを実行すると、

memo.js
crypto = require("crypto");

plainText = 'abcdefghijklmnopqrstuvwxyz';
passowrd = 'WIdlbs9pDHoLnLo4xEnVKc1DKA0XUFS0';
alg = 'aes256'
encoding = 'base64'  // 'binary' or 'hex'

cipher = crypto.createCipher(alg, passowrd);
cipheredText = cipher.update(plainText, 'utf8', encoding);
cipheredText += cipher.final(encoding);

decipher = crypto.createDecipher(alg, passowrd);
dec = decipher.update(cipheredText, encoding, 'utf8');
dec += decipher.final('utf8');

console.log('crypted: '+ cipheredText);
console.log('decrypted: ' + dec);

こんな感じになります。

% node memo.js
crypted: 6RM52ZdyXDsi+PtGBTB58L5SlgythPJfVlld2z65YPo=
decrypted: abcdefghijklmnopqrstuvwxyz
9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6