在最新的浏览器中是否有内建的JavaScript字符串散列函数? [英] is there any builtin javascript string hash function in newest browsers?

查看:106
本文介绍了在最新的浏览器中是否有内建的JavaScript字符串散列函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当浏览器出现新版本时,我都会听到有关正在添加的新内容的信息,比如说说webGL和其他技术,没有人真正知道它们是否赶上。

但我想知道是否有人曾经想过像JavaScript这样的基本东西,比如散列函数(MD5,SHA1之类)。



通过最新的浏览器,我的意思是今天的开发版本太喜欢Opera 12,Chrome 17或Firefox 10.

寻找解决方案我在这里找到了另一个线程的评论: 你知道javascript对象吗?已经是散列表?)。那么这些哈希表是什么?这是否意味着我可以将任何字符串转换为哈希值,但不是像md5或sha1这样的已建立的字符串,但是某些JS会在特定的情况下生成?



基本上我需要做的是:

  var txt =Hello world!; 
var hash = txt.toSha1();


解决方案

任何人仍然在寻找这些信息。有一个 WebCrypto API ,它似乎已在2017年初。



要在浏览器中使用它,您可以在 window.crypto.subtle 其中包含加密,摘要等方法。有关可用函数的文档此处 a>。


Everytime a new versions of browsers show up I hear about new stuff being added, like say webGL and other technologies that no one really knows if they catch up.

But I wonder if someone ever thought about such basic stuff in JS like hashing functions (MD5,SHA1 and the like).

By newest browsers I mean today's development versions too like Opera 12, Chrome 17 or Firefox 10.

Looking now for solution I found this comment on another thread here: https://stackoverflow.com/questions/7204097/short-hashing-function-for-javascript (Do you know that javascript objects already are hashtables ?). So what are these 'hashtables' ? Does it mean that I can make any string into a hash, but not an established one like md5 or sha1 but some JS build in specific ?

basically what I need to do is:

var txt="Hello world!";
var hash = txt.toSha1();

解决方案

For anybody still looking for this information. There is a WebCrypto API which appears to have been finalised at the beginning of 2017.

To use it in a browser, you can find it at window.crypto.subtle which contains methods for encryption, digests etc. Documentation on the available functions here.

这篇关于在最新的浏览器中是否有内建的JavaScript字符串散列函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆