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="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/md5.js">
</script>
</head>
<body>
<script>
var plaintext = "hiii";
var encrptedText = CryptoJs.md5(plaintext);
alert("Encrpted Text : " + encrptedText.toString());
</script>
</body>
</html>
CryptoJS is a growing collection of standard and secure cryptographic algorithms implemented in JavaScript using best practices and patterns. They are fast, and they have a consistent and simple interface.
Crypto is a module in Node. js which deals with an algorithm that performs data encryption and decryption. This is used for security purpose like user authentication where storing the password in Database in the encrypted form. Crypto module provides set of classes like hash, HMAC, cipher, decipher, sign, and verify.
crypto-js/hmac-sha256An HMAC is a message authentication code that uses a hash algorithm. In this example, an HMAC is demonstrated using the sha256 algorithm, but any supported algorithm will work. var hmac = CryptoJS.HmacSHA256("message", "secretkey");
To encrypt and decrypt data, simply use encrypt() and decrypt() function from an instance of crypto-js. var bytes = CryptoJS. AES. decrypt(ciphertext, 'my-secret-key@123');
Use the entire package - not just the md5 module - change the src
in your script
tag
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script></head>
<body>
<script>
var plaintext="hiii";
var encrptedText = CryptoJS.MD5(plaintext)
alert("Encrpted Text : "+ encrptedText.toString());
</script>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With