Referenceerror: Cryptojs Is Not Defined

Referenceerror: Cryptojs Is Not Defined

I tried to hash a text in client-side. I used following code to hash it, but it shows this Reference Error.

<html>

<head>
  <script src="">
  </script>
</head>

<body>
  <script>
    var plaintext = "hiii";
    var encrptedText = CryptoJs.md5(plaintext);
    alert("Encrpted Text : " + encrptedText.toString());
  </script>
</body>

</html>
3

2 Answers

Use the entire package - not just the md5 module - change the src in your script tag

<html>
<head>
<script src=""></script></head>
<body>
<script>
var plaintext="hiii";
var encrptedText = CryptoJS.MD5(plaintext)
alert("Encrpted Text : "+ encrptedText.toString());
</script>
 </body>
</html>

If for you important the size of extended libraries, that you can use pure-md5 (4.76kb) instead crypto-js (187.44kb).

<html>

<head>
<script src="">
  </script>
</head>

<body>
  <script>
    var plaintext = "hiii";
    var encrptedText = md5(plaintext);
    alert("Encrpted Text : " + encrptedText.toString());
  </script>
</body>

</html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.