Import private key returns error
I am using kbpgp-1.1.0.js in browser and am having trouble importing a private key.
I am not seeing the private key read into the armor private property on the key proto. The public key works fine. It appears the returned object does not have the private key property or unlock_pgp method.
TypeError: undefined is not a function at http://localhost:8100/js/services.js:985:24 at http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:4950:18 at Deferrals.exports.Deferrals.Deferrals._call (http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:26024:16) at http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:26036:26 at exports.trampoline.trampoline (http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:26002:14) at Deferrals.exports.Deferrals.Deferrals._fulfill (http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:26034:16) at http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:4946:28 at KeyManager.unlock_pgp (http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:4948:15) at http://localhost:8100/js/services.js:981:20 at http://localhost:8100/lib/kbpgp/rel/kbpgp-1.1.0.js:4915:18
kbpgp.KeyManager.import_from_armored_pgp({
armored: pair.publicKeyArmored
}, function(err, imported) {
if (!err) {
imported.merge_pgp_private({
armored: pair.privateKeyArmored
}, function(err) {
if (!err) {
if (imported.is_pgp_locked()) {
imported.unlock_pgp({
passphrase: pin
}, function(err) {
if (!err) {
var ring = new kbpgp.keyring.KeyRing;
var kms = [imported];
for (var i in kms) {
ring.add_key_manager(kms[i]);
}
kbpgp.unbox({keyfetch: ring, armored: msg }, function(err, literals) {
if (err != null) {
} else {
deferred.resolve(literals[0].toString());
}
});
}
});
}
}
});
}
});
Actually looks like the error is at:
var ring = new kbpgp.keyring.KeyRing();
Ah, it's a mismatch between the docs and the library. That class is exported as kbpgp.keyring.PgpKeyRing. I'll fix the library in 1.1.1 but for now, you can just rename the class. Cheers