From 2d678f8bb990f7ab98cbea69adc3b81e304fa5f5 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 2 Apr 2025 20:50:03 +0200 Subject: [PATCH] Add OpenPGPSecretKey.unlock(Passphrase) extension method --- .../bouncycastle/extensions/OpenPGPKeyExtensions.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/bouncycastle/extensions/OpenPGPKeyExtensions.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/bouncycastle/extensions/OpenPGPKeyExtensions.kt index 305bca15..06a7e8ed 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/bouncycastle/extensions/OpenPGPKeyExtensions.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/bouncycastle/extensions/OpenPGPKeyExtensions.kt @@ -7,10 +7,15 @@ package org.pgpainless.bouncycastle.extensions import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData import org.bouncycastle.openpgp.PGPSignature import org.bouncycastle.openpgp.api.OpenPGPKey +import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey +import org.pgpainless.util.Passphrase fun OpenPGPKey.getSecretKeyFor(pkesk: PGPPublicKeyEncryptedData): OpenPGPSecretKey? = this.getSecretKey(pkesk.keyIdentifier) fun OpenPGPKey.getSecretKeyFor(signature: PGPSignature): OpenPGPSecretKey? = this.getSecretKey(signature.fingerprint!!.keyIdentifier) + +fun OpenPGPKey.OpenPGPSecretKey.unlock(passphrase: Passphrase): OpenPGPPrivateKey = + this.unlock(passphrase.getChars())