Skip to content

Instantly share code, notes, and snippets.

@sorpaas
Last active February 10, 2017 12:43
Show Gist options
  • Save sorpaas/9e2f9056ced56b1f583bbdc63050b50c to your computer and use it in GitHub Desktop.
Save sorpaas/9e2f9056ced56b1f583bbdc63050b50c to your computer and use it in GitHub Desktop.
Decrypting GPG Messages Using Subkeys
var openpgp = require("openpgp");
var fs = require("fs");
var key = fs.readFileSync("<armored key file>", "utf8");
var skey = openpgp.key.readArmored(key).keys[0];
skey.decrypt("<key password>");
var message = fs.readFileSync("<armored message>", "utf8");
var m = openpgp.message.readArmored(message);
var options = {
message: m,
privateKey: skey
};
openpgp.decrypt(options).then(function(plaintext) {
console.log(plaintext);
});
diff --git a/src/key.js b/src/key.js
index 5669188..e0e66b9 100644
--- a/src/key.js
+++ b/src/key.js
@@ -49,9 +49,6 @@ export function Key(packetlist) {
this.users = null;
this.subKeys = null;
this.packetlist2structure(packetlist);
- if (!this.primaryKey || !this.users) {
- throw new Error('Invalid key: need at least key and user ID packet');
- }
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment