JavaScript 활용팁
2017.05.29 / 10:20

Javascript 암호화 하기

추천 수 221

Javascript 로 암호화 할 일이 생겨서 Search 중 발견 했다.

※ github -

보통 서버에서 암호화 작업을 하거나, SSL 을 사용 하는대 어쩔 수 없이 암호화 를 하는 점도 있는거 같다.

단방향 암호화 알고리즘 사용에는 편리 한것 같다. 

적용 방법

소스 다운 후 아래와 같이 적용 한다. 다른 알고리즘을 사용할 경우 다른 js를 사용 한다.

<script type="text/javascript" src="/core.js"></script>
<script type="text/javascript" src="/sha256.js"></script>


출처: [White Life Story]


This repository is a mirror of crypto-js from Google Code. Its full history has been converted with svn2git, yet it is not guaranteed to track more recent changes. Other than that, several branches have been created for working on some extra stuffs.


SEED-128 is a block cipher which shows extensive and exclusive use in South Korea. It features a so-called Feistel network seemingly not very different from other predecessors like DES. If necessary, various options including IV, block modes, and/or padding, can be specified as original CryptoJS syntax.

<script src=""></script>
    var encrypted = CryptoJS.SEED.encrypt("Message", "Secret Passphrase");
    var decrypted = CryptoJS.SEED.decrypt(encrypted, "Secret Passphrase");


CP949 is a character encoding for Korean language. In the current UTF-8 era, it still has widespread adoption among many domestic corporate sites. In short, there are plenty of seed-encrypted packets whose source is in CP949. Be cautious of its insane filesize: ~170 kB

<script src=""></script>
    var words = CryptoJS.enc.CP949.parse('?沮d');
    var cp949 = CtyptoJS.enc.CP949.stringify(words);


PBKDF1 is a key derivation function superseded by more robust PBKDF2. While any supported hash functions can be used, keys longer than the hash digest cannot be derived.

<script src=""></script>
    var salt = CryptoJS.lib.WordArray.random(128/8);
    var sha1 = CryptoJS.algo.SHA1;
    var key = CryptoJS.PBKDF1("Secret Passphrase", salt, { keySize: 128/32, hasher: sha1, iterations: 1000 });


RC2 is a block cipher whose details were kept secret for a decade. Although it has been superseded by many other recent algorithms, there are some legacy systems still dependent on. The effective key length is 32 bits by default, while it can be specified up to 1024 bits.

<script src=""></script>
    var encrypted = CryptoJS.RC2.encrypt("Message", "Secret Passphrase", { effectiveKeyBits: 64 });
    var decrypted = CryptoJS.RC2.decrypt(encrypted, "Secret Passphrase", { effectiveKeyBits: 64 });