如何使用Web Crypto生成密钥对并在Firefox AddOn中访问密钥? [英] How do I generate a key pair with Web Crypto and access its keys in a Firefox AddOn?

查看:175
本文介绍了如何使用Web Crypto生成密钥对并在Firefox AddOn中访问密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Firefox AddOn中调用 window.crypto.subtle.generateKey 。由于我无法在 main.js 中访问 window ,所以我创建了一个 page-worker 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')
});

我可以调用 window.crypto.subtle.generateKey in call-web-crypto.js ,但我无法访问生成的密钥对的密钥属性:



XrayWrapper拒绝访问属性publicKey(原因:值与目标值不同)。请参阅 https://developer.mozilla.org/en-US/docs/Xray_vision了解更多信息。请注意,只有从给定的全局对象的第一个被拒绝的属性访问将被报告。

如何生成一个密钥对,并在我的Firefox插件访问它的键?您可以在 main.js
$ b

解决方案 b

  const {Cu} = require(chrome); 
Cu.importGlobalProperties([crypto]);

然后你就可以访问 crypto.subtle.generateKey 以及所有其他 crypto goodness ... note no window


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?

解决方案

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

这篇关于如何使用Web Crypto生成密钥对并在Firefox AddOn中访问密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆