How do I generate a key pair with Web Crypto and access its keys in a Firefox AddOn?

那年仲夏 提交于 2019-12-31 03:46:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!