“이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.”
AES 방식(Key)
var key = 'this is password key';
var input = 'This_is_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);
http://oraclejavastudy.tistory.com/entry/Nodejs-%EA%B0%95%EC%A2%8C-%EC%9E%90%EB%A3%8C-crypto-%EB%AA%A8%EB%93%88
RSA 방식(public.key, private.key)
var crypto = require('crypto');
//openssl genrsa -out private.key 2048
//openssl rsa -in private.key -out public.key -pubout
var PUBKEY = fs.readFileSync(__dirname+'/public.key');
var PRIVKEY = fs.readFileSync(__dirname+'/private.key');
// RSA PRIVATE ENCRYPT -> PUBLIC DECRYPT //
myMSG = "This_is_Password!";
function privENC_pubDEC(originMSG){
encmsg = crypto.privateEncrypt(PRIVKEY, Buffer.from(originMSG, 'utf8') ).toString('base64');
msg = crypto.publicDecrypt(PUBKEY, Buffer.from(encmsg, 'base64'));
console.log("Encrypted with private key : "+encmsg);
console.log(msg.toString());
}
function pubENC_privDEC(originMSG){
encmsg = crypto.publicEncrypt(PUBKEY, Buffer.from(originMSG, 'utf8') ).toString('base64');
msg = crypto.privateDecrypt(PRIVKEY, Buffer.from(encmsg, 'base64'));
console.log("\nEncrypted with public key : "+encmsg);
console.log(msg.toString());
}
privENC_pubDEC(myMSG);
pubENC_privDEC(myMSG);
http://indienote.tistory.com/253