我在我的应用程序中使用了一个openPgpJs库,它是由Apache创建的。
下面是代码的一部分:
var publicKey = openpgp.key.readArmored(_publicKey);
openpgp.encryptMessage(publicKey.keys, text).then(function (pgpMessage) {
// success
callback(pgpMessage);
}).catch(function (error) {
// failure
console.error(error);
});它工作得很好,但在WP8上却不行。如果失败,将导致openpgp var未定义。在该库源代码中,有这样的代码:
!function (e) {
"object" == typeof exports ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : "undefined" != typeof window ? window.openpgp = e() : "undefined" != typeof global ? global.openpgp = e() : "undefined" != typeof self && (self.openpgp = e())}
因此,应该定义openpgp。我怎么才能让它起作用?
更新,我添加了var openpgp = window.openpgp;,错误消失了。现在它无法加密消息,而且很难调试,因为库代码被缩小了
发布于 2015-05-18 13:08:47
所以,对于任何有同样问题的人来说。
var openpgp = window.openpgp;避免“未定义”错误。getRandomValues函数内部--有一个异常No secure random number generator available.。为了避免此错误,我将最后一个(有例外)语句更改为var sjcl = window.sjcl; if (sjcl.random.isReady()) { var buf = new Uint8Array(1); bytes = sjcl.random.randomWords(buf.length); buf.set(bytes); }else{ var bytes = []; for (var i = 0; i < buf.length; i++) { bytes.push(isaac.rand()); buf.set(bytes); } } @ZeroG对这个问题的回答:确保javascript中的随机数字安全?
希望它能对某人有所帮助
https://stackoverflow.com/questions/30254759
复制相似问题