써먹는 웹개발

[Node.js] 암호화/복호화 본문

Server/Node.js

[Node.js] 암호화/복호화

kmhan 2023. 4. 24. 10:47


728x90
반응형

1. 암호화

1
2
3
4
5
6
7
8
const algorithm = 'aes-256-cbc';
const key = 'abcdefghijklmnopqrstuvwxyz123456';
const iv = '1234567890123456';
 
const cipher = crypto.createCipheriv(algorithm, key , iv );
let cryptoEmail = cipher.update(user?.email, 'utf8', 'base64');
// 아래 안 적으면 복호화 안됨
cryptoEmail += cipher.final('base64');
cs

 

2. 복호화

1
2
3
4
const decipher = crypto.createDecipheriv(algorithm, key , iv);
let decodeEmail = decipher.update(cryptoEmail,'base64','utf8');
// 아래 안 적으면 복호화 안됨
decodeEmail += decipher.final('utf8');
cs
728x90
반응형


Comments