[英]openpgp.js on wp8 error
我在使用Apache Cordova创建的应用程序中使用openPgpJs库。
这是代码的一部分:
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;
错误消失了。 现在,它很难对消息进行加密-并且很难调试,因为库代码已缩小
因此,对于任何来这里遇到同样问题的人。
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); } }
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中保护随机数?
希望它可以帮助某人=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.