问题
I'd like to call window.crypto.subtle.generateKey
in my Firefox AddOn. Since I can not access window
in main.js I create a page-worker with a content script:
var self = require('sdk/self');
var cryptoScript = require('sdk/page-worker').Page({
contentURL: self.data.url('empty.html'),
contentScriptFile: self.data.url('call-web-crypto.js')
});
I can call window.crypto.subtle.generateKey
in call-web-crypto.js, but I can not access the key properties of the generated key pair:
XrayWrapper denied access to property publicKey (reason: value not same-origin with target). See https://developer.mozilla.org/en-US/docs/Xray_vision for more information. Note that only the first denied property access from a given global object will be reported.
How can I generate a key pair and access its keys in my Firefox Addon?
回答1:
in main.js you can ...
const { Cu } = require("chrome");
Cu.importGlobalProperties(["crypto"]);
then you'll have access to crypto.subtle.generateKey
as well as all the other crypto
goodness ... note no window
来源:https://stackoverflow.com/questions/33562588/how-do-i-generate-a-key-pair-with-web-crypto-and-access-its-keys-in-a-firefox-ad