![](/img/trans.png)
[英]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.