Arpit Jain
Arpit Jain

Reputation: 1

How to write a Javascipt code to create a hash string of less than or equal to 20 bytes for an input of any string?

I have multiple strings (containing alphanumeric characters) such as:

And so on.

I want to convert these strings to a hash of less than or equal to 20 bytes. Is there a JS function which can do this? I am specifically looking for the output to be less than or equal to 20 bytes.

Upvotes: 0

Views: 79

Answers (1)

AyushKatiyar
AyushKatiyar

Reputation: 1030

Try using : First install bower (A package manager for web)

npm install -g bower

Go to the location where the project is located in the terminal and run following command:

bower install crypto-js

Add the following code in HTML file:

<script type="text/javascript" src="path-to/bower_components/crypto-js/crypto-js.js"></script>
<script type="text/javascript">
    var hash = CryptoJS.MD5("message");// returns 16 bytes hash code
    console.log(hash.toString());
</script>

Here path-to represents the relative path to bower_components folder that was created by the execution of bower install crypto-js

Hope this helps. For reference visit https://github.com/brix/crypto-js

Upvotes: 1

Related Questions