diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index ddde4b15..accb225b 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -224,7 +224,7 @@ SecretKey.prototype.write = function () { // - [Optional] If secret data is encrypted (string-to-key usage octet // not zero), an Initial Vector (IV) of the same length as the // cipher's block size. - if (this.s2k_usage) { + if (this.s2k_usage && this.s2k.type !== 'gnu-dummy') { optionalFieldsArr.push(...this.iv); } @@ -385,6 +385,11 @@ SecretKey.prototype.generate = async function (bits, curve) { * Clear private params, return to initial state */ SecretKey.prototype.clearPrivateParams = function () { + if (this.s2k && this.s2k.type === 'gnu-dummy') { + this.isEncrypted = true; + return; + } + if (!this.keyMaterial) { throw new Error('If secret key is not encrypted, clearing private params is irreversible.'); } diff --git a/src/type/s2k.js b/src/type/s2k.js index 02d86f36..99ea32ca 100644 --- a/src/type/s2k.js +++ b/src/type/s2k.js @@ -117,6 +117,10 @@ S2K.prototype.read = function (bytes) { * @returns {Uint8Array} binary representation of s2k */ S2K.prototype.write = function () { + if (this.type === 'gnu-dummy') { + return new Uint8Array([101, 0, ...util.str_to_Uint8Array('GNU'), 1]); + } + const arr = [new Uint8Array([enums.write(enums.s2k, this.type), enums.write(enums.hash, this.algorithm)])]; switch (this.type) {