Node.js 강좌 자료] crypto 모듈

 

Node.js 강좌 자료] crypto 모듈

 

 

 

 

실무개발자를위한 실무교육 전문교육센터학원
www.oraclejava.co.kr에 오시면 보다 다양한 강좌를 보실 수 있습니다.

 

 

 

 

 

crypto 모듈

 

 

 - 모듈 임포트

  : var crypto = require('crypto');

 

 - 예제

  :

var crypto = require('crypto');

var shasum = crypto.createHash('sha256');  shasum.update('crypto_hash');

var output = shasum.digest('hex');

console.log('crypto_hash:', output);

 

 

crypto_hash:  820f329baab52f75e1e3844b61b7bfcaa4035d881c6f1fbd42dc29b024638c05

var crypto = require('crypto');

var key = 'this is password key'; 

var input = 'PASSWORD';

var cipher = crypto.createCipher('aes192', key); 

cipher.update(input, 'utf8', 'base64');

var cipheredOutput = cipher.final('base64');

 

var decipher = crypto.createDecipher('aes192', key); 

decipher.update(cipheredOutput, 'base64', 'utf8'); 

var decipheredOutput = decipher.final('utf8');

​console.log('original string: ' + input);

​console.log('ciphered string: ' + cipheredOutput);

​console.log('deciphered string: ' + decipheredOutput);

 

 

 

original string: PASSWORD

ciphered string: mWFzjy6EQpB/OEXGQsojeQ==  deciphered string: PASSWORD

 

 

 

+ Recent posts