TIL ( crypto-js ๋)
2024. 7. 23. 23:21ใTIL
๐กcrypto-js
์์
- crypto-js๋ ์๋ฐ์คํธ๋ฆฝํธ์์ ํด์ ํจ์๋ฅผ ํตํด ์ํธํ๋ฅผ ํ ์ ์๊ฒ ํด์ฃผ๋ node.js ํจํค์ง์ด๋ค.
- ๋ค์ํ ์ํธํ ๋ฐ ํด์ ์๊ณ ๋ฆฌ์ฆ์ ์ ๊ณตํ๋ฉฐ ์ฝ๊ฒ ์ค์นํ๊ณ ์ฌ์ฉํ ์ ์๋ค.
- ๋ณด์์ด ์ค์ํ ํ๋ก์ ํธ์์ ์ ์ฉํ๊ฒ ์ฌ์ฉ๋ ์ ์๋ค.
์ํธํ ๋ฐฉ์
- ๋์นญํค (Symmetric Encryption): ์ํธํ - ๋ณตํธํ ํ ๋ ๊ฐ์ ํค๊ฐ์ ์ด์ฉํ๋ค
- ๋น๋์นญํค(Asymmetric Encryption) : ์ํธํ - ๋ณตํธํ ํ ๋ ๋ค๋ฅธ ํค๊ฐ์ ์ด์ฉํ๋ค
- ํด์ฑ (hashing) : ๋จ๋ฐฉํฅ์ผ๋ก ์ํธํ๋ง ๊ฐ๋ฅํ๊ณ ๋ณตํธํ ํ ์ ์๋ค. ( ๋น๋ฐ๋ฒํธ ๋ฑ์ ์ด์ฉํจ)
์ฌ์ฉ๋ฐฉ๋ฒ
1. crypto-js ์ค์น
npm install crypto-js
2. ์ฌ์ฉ ์์
const CryptoJS = require("crypto-js");
// ์ํธํ
const message = "Hello, World!";
const secretKey = "mySecretKey";
const encrypted = CryptoJS.AES.encrypt(message, secretKey).toString();
console.log("Encrypted:", encrypted);
// ๋ณตํธํ
const bytes = CryptoJS.AES.decrypt(encrypted, secretKey);
const decrypted = bytes.toString(CryptoJS.enc.Utf8);
console.log("Decrypted:", decrypted);
'TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
TIL(swagger์ฌ์ฉํ๊ธฐ) (0) | 2024.07.25 |
---|---|
TIL(Proxy) (2) | 2024.07.24 |
TIL ( ํํ๋ก์ ํธ-์ด๊ธฐ์ค๊ณ ) (0) | 2024.07.22 |
TIL ( ๋ถํํ ์คํธ ) (0) | 2024.07.19 |
TIL ( Trello ํ๋ก์ ํธ ํ๊ณ ) (0) | 2024.07.18 |