Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2013-05-18 03:11:06 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2013-05-18 03:11:06 +0400
commitecc849da20a41aee8b4c6451015eca26dc3f1fb8 (patch)
tree7d92e1d557079cec47f8a10620bf05de2e3b7610
parent297de902c71c338522bc37401206d609ee0e8fa9 (diff)
deprecated old style methods, added new style which uses isPrivateKeyEmpty() as well.
-rw-r--r--src/main/java/org/bouncycastle/openpgp/PGPSecretKeyRing.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/org/bouncycastle/openpgp/PGPSecretKeyRing.java b/src/main/java/org/bouncycastle/openpgp/PGPSecretKeyRing.java
index fd66178f..2e30e737 100644
--- a/src/main/java/org/bouncycastle/openpgp/PGPSecretKeyRing.java
+++ b/src/main/java/org/bouncycastle/openpgp/PGPSecretKeyRing.java
@@ -20,6 +20,8 @@ import org.bouncycastle.bcpg.SecretKeyPacket;
import org.bouncycastle.bcpg.SecretSubkeyPacket;
import org.bouncycastle.bcpg.TrustPacket;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
+import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
+import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
/**
@@ -312,6 +314,7 @@ public class PGPSecretKeyRing
* @param newEncAlgorithm the algorithm to be used for the encryption.
* @param rand source of randomness.
* @param provider name of the provider to use
+ * @deprecated use version taking PBESecretKeyEncryptor/PBESecretKeyDecryptor
*/
public static PGPSecretKeyRing copyWithNewPassword(
PGPSecretKeyRing ring,
@@ -335,6 +338,7 @@ public class PGPSecretKeyRing
* @param newEncAlgorithm the algorithm to be used for the encryption.
* @param rand source of randomness.
* @param provider provider to use
+ * @deprecated use version taking PBESecretKeyEncryptor/PBESecretKeyDecryptor
*/
public static PGPSecretKeyRing copyWithNewPassword(
PGPSecretKeyRing ring,
@@ -356,6 +360,40 @@ public class PGPSecretKeyRing
}
/**
+ * Return a copy of the passed in secret key ring, with the private keys (where present) associated with the master key and sub keys
+ * are encrypted using a new password and the passed in algorithm.
+ *
+ * @param ring the PGPSecretKeyRing to be copied.
+ * @param oldKeyDecryptor the current decryptor based on the current password for key.
+ * @param newKeyEncryptor a new encryptor based on a new password for encrypting the secret key material.
+ * @return the updated key ring.
+ */
+ public static PGPSecretKeyRing copyWithNewPassword(
+ PGPSecretKeyRing ring,
+ PBESecretKeyDecryptor oldKeyDecryptor,
+ PBESecretKeyEncryptor newKeyEncryptor)
+ throws PGPException
+ {
+ List newKeys = new ArrayList(ring.keys.size());
+
+ for (Iterator keys = ring.getSecretKeys(); keys.hasNext();)
+ {
+ PGPSecretKey key = (PGPSecretKey)keys.next();
+
+ if (key.isPrivateKeyEmpty())
+ {
+ newKeys.add(key);
+ }
+ else
+ {
+ newKeys.add(PGPSecretKey.copyWithNewPassword(key, oldKeyDecryptor, newKeyEncryptor));
+ }
+ }
+
+ return new PGPSecretKeyRing(newKeys, ring.extraPubKeys);
+ }
+
+ /**
* Returns a new key ring with the secret key passed in either added or
* replacing an existing one with the same key ID.
*