按照
Deprecations and Removals in Chrome 60
:
crypto.minary现在需要一个安全的来源
这个
Web Crypto API
自从Chrome37在非安全源代码上工作以来,就一直得到支持。因为铬的长期政策
preferring secure origins for powerful features
,
crypto.subtle
现在只在安全来源上可见。
Intent to Remove
γ
Chromium Bug
在https服务器上放置以下代码时,
密码学的
而且工作得很好
<!DOCTYPE html>
<html>
<body>
<input id="start" type="button" value="Start">
<script>
function getWorkerJS() {
var js = `
onmessage = function(e) {
var jwkKey = {
kty: "oct",
k: "lckjnFLIEas7yf65ca6saksjhcajs554s5cajshgGGG"
};
crypto.subtle.importKey(
"jwk", jwkKey, {name: "AES-CBC"}, true,
['encrypt', 'decrypt', 'wrapKey', 'unwrapKey']
)
.then(
function (result) {
postMessage({ success: true});
},
function (error) {
postMessage({ message: error.message });
}
);
};
`;
var blob = new Blob([js], {"type": "text/plain"});
return URL.createObjectURL(blob);
}
var ww = new Worker(getWorkerJS());
ww.onmessage = function(msg) {
console.log(msg.data);
};
document.getElementById('start').addEventListener('click', start, false);
function start() {
ww.postMessage('start');
}
</script>
</body>
</html>