diff --git a/src/key.js b/src/key.js index 3fc308d0..8437520e 100644 --- a/src/key.js +++ b/src/key.js @@ -916,6 +916,10 @@ function generate(options) { if (options.keyType !== enums.publicKey.rsa_encrypt_sign) { throw new Error('Only RSA Encrypt or Sign supported'); } + // Key without passphrase is unlocked by definition + if (!options.passphrase) { + options.unlocked = true; + } var packetlist = new packet.List(); diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index be3cc5aa..8877b917 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -279,6 +279,9 @@ SecretKey.prototype.generate = function (bits) { * Clear private MPIs, return to initial state */ SecretKey.prototype.clearPrivateMPIs = function () { + if (!this.encrypted) { + throw new Error('If secret key is not encrypted, clearing private MPIs is irreversible.'); + } this.mpi = this.mpi.slice(0, crypto.getPublicMpiCount(this.algorithm)); this.isDecrypted = false; }; diff --git a/test/general/signature.js b/test/general/signature.js index 1da22c0e..e4b7ebeb 100644 --- a/test/general/signature.js +++ b/test/general/signature.js @@ -636,4 +636,13 @@ describe("Signature", function() { expect(result[0].valid).to.be.true; }); + it('Sign message with key without password', function() { + var key = openpgp.generateKeyPair({numBits: 512, userId: 'ABC', passphrase: null}).key; + + var message = openpgp.message.fromText('hello world'); + message = message.sign([key]); + + expect(message).to.exist; + }); + });