[英]How to override functions from the Web API when writing a Firefox addon?
[英]Using the Web Crypto API from Firefox AddOn
我不知道如何从AddOn脚本本身访问Web Crypto API(无文档)。
从内容脚本尝试执行此操作会导致访问权限错误, then
:
JavaScript error:
resource://gre/modules/commonjs/toolkit/loader.js ->
resource://gre/modules/commonjs/sdk/loader/sandbox.js ->
resource://..../data/content-script.js,
line 36: Error: Permission denied to access property "then"
相关代码为:
var password = new TextEncoder("utf-8").encode('password');
var salt = new TextEncoder("utf-8").encode('salt');
var iterations = 1;
var outputLen = 20;
return window.crypto.subtle.importKey(
"raw", password, {"name": "PBKDF2"}, false, ["deriveKey"]
).then(function(baseKey) {
return window.crypto.subtle.deriveKey(
{ "name": "PBKDF2",
"salt": salt,
"iterations": iterations,
"hash": "SHA-1",
},
baseKey, // input key
{"name": "AES-CBC", "length": 32*8}, // output key use and size
true, // output key is extractable
["encrypt","decrypt"]); // output key capabilities
}).then(function(aesKey) {
return window.crypto.subtle.exportKey("raw", aesKey);
}).then(function(keyBytes) {
var keyArray = Array.slice(new Uint8Array(keyBytes), 0, outputLen);
keyArray.toHex = toHex;
keyArray.toPassword = toPassword;
return keyArray;
});
是否有require
将Web Crypto API集成到加载项中,或者有什么我可以做才能使这项工作有效? 由于运行时方面的考虑,我真的不想使用JS加密库(PBKDF2运行快→选择更多的迭代→更安全)。
Components.utils.importGlobalProperties(['crypto']);
var blah = crypto.subtle.deriveKey({....});
从这里获取: https : //developer.mozilla.org/en-US/docs/Components.utils.importGlobalProperties
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.