본문 바로가기

자료

JS,PHP CryptoJS

728x90
// INIT
var myString   = "";
var myPassword = "";


// PROCESS
var encrypted = CryptoJS.AES.encrypt(myString, myPassword);
var decrypted = CryptoJS.AES.decrypt(myString, myPassword);
document.getElementById("demo0").innerHTML = myString;
document.getElementById("demo1").innerHTML = encrypted;
document.getElementById("demo2").innerHTML = decrypted;
document.getElementById("demo3").innerHTML = decrypted.toString(CryptoJS.enc.Utf8);

<html lang="es">

<head>
  <meta charset="utf-8">

  <title>CryptoJS Example</title>
  <meta name="description" content="CryptoJs Example">
  <meta name="author" content="Gabriel Porras">

  <!--
  https://cdnjs.com/libraries/crypto-js
  -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
  
  
  <!--[if lt IE 9]>
    <script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
</head>

<body>
</body>

  
  <strong><label>Original String:</label></strong>
  <span id="demo0"></span>

  <br>
  <br>
  
  <strong><label>Encrypted:</label></strong>
  <span id="demo1"></span>

  <br>
  <br>
  
  <strong><label>Decrypted:</label></strong>
  <span id="demo2"></span>

  <br> 
  <br>

  <strong><label>String after Decryption:</label></strong>
  <span id="demo3"></span>

  
  <br />
  <br />
  
  <strong style="color: red;">CryptoJS is no longer maintained. Take a look of another JS Crypto Libraries in my <a href="https://github.com/gabrielizalo/JavaScript-Crypto-Libraries" target="_blank">GibHub List</a></strong>.
  
</html>
728x90