Is there a built-in javascript hash function in newer browsers?

Every time new versions of browsers appear, I hear about the addition of new material, for example, webGL and other technologies that no one knows if they catch up.

But I'm wondering if anyone was thinking about such basic things in JS as hash functions (MD5, SHA1, etc.).

In the latest browsers, I mean development versions today, such as Opera 12, Chrome 17 or Firefox 10.

Looking now at the solution, I found this comment on another post here: https://stackoverflow.com/questions/7204097/short-hashing-function-for-javascript ( Do you know that javascript objects are already hashtables? ). So what are these hash tables? Does this mean that I can make any line in the hash, but not set, for example, md5 or sha1, but some JS are built in a specific one?

basically what i need to do:

var txt="Hello world!"; var hash = txt.toSha1(); 
+6
source share
3 answers

For those who are still looking for this information. There is a WebCrypto API that appears to have been completed in early 2017.

To use it in a browser, you can find it in window.crypto.subtle , which contains encryption methods, digests, etc. The documentation of available features is here .

+3
source

Paul Johnston implemented the following algorithms in javascript

MD5, RIPEMD-160, SHA-1, SHA-256 and sha-512

Here you can find the source code and some examples: http://pajhome.org.uk/crypt/md5/

Hope this is what you were looking for.

0
source

When I need simple hashing of the client side without external libraries, I use the built-in functions of the browser atob() and btoa() .

window.btoa () creates an ASCII string encoded with base-64 from the binary string "string".

 function utf8_to_b64( str ) { return window.btoa(encodeURIComponent( escape( str ))); } 

The window.atob () function decodes a data string that has been encoded using base-64 encoding.

 function b64_to_utf8( str ) { return unescape(decodeURIComponent(window.atob( str ))); } 

http://caniuse.com/#search=btoa and http://caniuse.com/#search=atob shows this is supported by modern browsers

Example from https://developer.mozilla.org/en-US/docs/Web/API/window.btoa

Note. The above solution is not dependent on an external library. As mentioned above, use this for simple encryption only. If you are looking for a secure cryptographic solution, do not use this.

-7
source

Source: https://habr.com/ru/post/904682/


All Articles