javascript - openpgp.js on wp8 error -
i'm using openpgpjs library in app, created apache cordova.
here's part of code:
var publickey = openpgp.key.readarmored(_publickey); openpgp.encryptmessage(publickey.keys, text).then(function (pgpmessage) { // success callback(pgpmessage); }).catch(function (error) { // failure console.error(error); });
it works fine not on wp8. if fails, 'cause openpgp
var undefined. in library source there's such code @ beginning:
!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())
}
so openpgp
should defined. how can make work?
update i've added var openpgp = window.openpgp;
, error disappeared. joust fails encrypt message - , it's hard debug, cause library code minified
so, came here same problems.
- use
var openpgp = window.openpgp;
avoid "undefined" error. - the next problem inside
getrandomvalues
function - there exceptionno secure random number generator available.
. avoid error i've changed last (with exception) statement
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 = []; (var = 0; < buf.length; i++) { bytes.push(isaac.rand()); buf.set(bytes); } }
according @zerog answer question: secure random numbers in javascript?
hope can =)
Comments
Post a Comment