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>2014-04-22 04:24:39 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-04-22 04:24:39 +0400
commit28ba2d3c368ecc515a54b0c5df1901c3b7d1f859 (patch)
treec72c7e541b1e3be210bf4a99570625bda5f9f65c
parentfc9f9d428ec82f65ce88603298e3236ec75b5930 (diff)
removal of deprecated methods.
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPKeyRingGenerator.java121
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java71
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java53
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java16
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPKeyRingTest.java27
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPRSATest.java4
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java4
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/PGPKeyRingTest.java24
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java10
9 files changed, 40 insertions, 290 deletions
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyRingGenerator.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyRingGenerator.java
index 83c034bf..a5f84b4f 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyRingGenerator.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPKeyRingGenerator.java
@@ -1,20 +1,13 @@
package org.bouncycastle.openpgp;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
-import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.bcpg.PublicSubkeyPacket;
import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor;
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
-import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
-import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
-import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
/**
* Generator for a PGP master and subkey ring. This class will generate
@@ -30,114 +23,6 @@ public class PGPKeyRingGenerator
private PGPSignatureSubpacketVector hashedPcks;
private PGPSignatureSubpacketVector unhashedPcks;
private PGPContentSignerBuilder keySignerBuilder;
-
- /**
- * Create a new key ring generator using old style checksumming. It is recommended to use
- * SHA1 checksumming where possible.
- *
- * @param certificationLevel the certification level for keys on this ring.
- * @param masterKey the master key pair.
- * @param id the id to be associated with the ring.
- * @param encAlgorithm the algorithm to be used to protect secret keys.
- * @param passPhrase the passPhrase to be used to protect secret keys.
- * @param hashedPcks packets to be included in the certification hash.
- * @param unhashedPcks packets to be attached unhashed to the certification.
- * @param rand input secured random
- * @param provider the provider to use for encryption.
- *
- * @throws PGPException
- * @throws NoSuchProviderException
- * @deprecated use method taking PBESecretKeyDecryptor
- */
- public PGPKeyRingGenerator(
- int certificationLevel,
- PGPKeyPair masterKey,
- String id,
- int encAlgorithm,
- char[] passPhrase,
- PGPSignatureSubpacketVector hashedPcks,
- PGPSignatureSubpacketVector unhashedPcks,
- SecureRandom rand,
- String provider)
- throws PGPException, NoSuchProviderException
- {
- this(certificationLevel, masterKey, id, encAlgorithm, passPhrase, false, hashedPcks, unhashedPcks, rand, provider);
- }
-
- /**
- * Create a new key ring generator.
- *
- * @param certificationLevel the certification level for keys on this ring.
- * @param masterKey the master key pair.
- * @param id the id to be associated with the ring.
- * @param encAlgorithm the algorithm to be used to protect secret keys.
- * @param passPhrase the passPhrase to be used to protect secret keys.
- * @param useSHA1 checksum the secret keys with SHA1 rather than the older 16 bit checksum.
- * @param hashedPcks packets to be included in the certification hash.
- * @param unhashedPcks packets to be attached unhashed to the certification.
- * @param rand input secured random
- * @param provider the provider to use for encryption.
- *
- * @throws PGPException
- * @throws NoSuchProviderException
- * @deprecated use method taking PBESecretKeyDecryptor
- */
- public PGPKeyRingGenerator(
- int certificationLevel,
- PGPKeyPair masterKey,
- String id,
- int encAlgorithm,
- char[] passPhrase,
- boolean useSHA1,
- PGPSignatureSubpacketVector hashedPcks,
- PGPSignatureSubpacketVector unhashedPcks,
- SecureRandom rand,
- String provider)
- throws PGPException, NoSuchProviderException
- {
- this(certificationLevel, masterKey, id, encAlgorithm, passPhrase, useSHA1, hashedPcks, unhashedPcks, rand, PGPUtil.getProvider(provider));
- }
-
- /**
- * Create a new key ring generator.
- *
- * @param certificationLevel the certification level for keys on this ring.
- * @param masterKey the master key pair.
- * @param id the id to be associated with the ring.
- * @param encAlgorithm the algorithm to be used to protect secret keys.
- * @param passPhrase the passPhrase to be used to protect secret keys.
- * @param useSHA1 checksum the secret keys with SHA1 rather than the older 16 bit checksum.
- * @param hashedPcks packets to be included in the certification hash.
- * @param unhashedPcks packets to be attached unhashed to the certification.
- * @param rand input secured random
- * @param provider the provider to use for encryption.
- *
- * @throws PGPException
- * @throws NoSuchProviderException
- * @deprecated use method taking PBESecretKeyEncryptor
- */
- public PGPKeyRingGenerator(
- int certificationLevel,
- PGPKeyPair masterKey,
- String id,
- int encAlgorithm,
- char[] passPhrase,
- boolean useSHA1,
- PGPSignatureSubpacketVector hashedPcks,
- PGPSignatureSubpacketVector unhashedPcks,
- SecureRandom rand,
- Provider provider)
- throws PGPException, NoSuchProviderException
- {
- this.masterKey = masterKey;
- this.hashedPcks = hashedPcks;
- this.unhashedPcks = unhashedPcks;
- this.keyEncryptor = new JcePBESecretKeyEncryptorBuilder(encAlgorithm).setProvider(provider).setSecureRandom(rand).build(passPhrase);
- this.checksumCalculator = convertSHA1Flag(useSHA1);
- this.keySignerBuilder = new JcaPGPContentSignerBuilder(masterKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1);
-
- keys.add(new PGPSecretKey(certificationLevel, masterKey, id, checksumCalculator, hashedPcks, unhashedPcks, keySignerBuilder, keyEncryptor));
- }
/**
* Create a new key ring generator.
@@ -263,10 +148,4 @@ public class PGPKeyRingGenerator
return new PGPPublicKeyRing(pubKeys);
}
-
- private static PGPDigestCalculator convertSHA1Flag(boolean useSHA1)
- throws PGPException
- {
- return useSHA1 ? new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1) : null;
- }
}
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java
index ab0babe7..a8b6692b 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java
@@ -3,9 +3,6 @@ package org.bouncycastle.openpgp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
-import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -24,7 +21,6 @@ import org.bouncycastle.bcpg.TrustPacket;
import org.bouncycastle.bcpg.UserAttributePacket;
import org.bouncycastle.bcpg.UserIDPacket;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
-import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter;
import org.bouncycastle.util.Arrays;
/**
@@ -87,42 +83,6 @@ public class PGPPublicKey
}
}
}
-
- /**
- * Create a PGPPublicKey from the passed in JCA one.
- * <p>
- * Note: the time passed in affects the value of the key's keyID, so you probably only want
- * to do this once for a JCA key, or make sure you keep track of the time you used.
- *
- * @param algorithm asymmetric algorithm type representing the public key.
- * @param pubKey actual public key to associate.
- * @param time date of creation.
- * @param provider provider to use for underlying digest calculations.
- * @throws PGPException on key creation problem.
- * @throws NoSuchProviderException if the specified provider is required and cannot be found.
- * @deprecated use JcaPGPKeyConverter.getPGPPublicKey()
- */
- public PGPPublicKey(
- int algorithm,
- PublicKey pubKey,
- Date time,
- String provider)
- throws PGPException, NoSuchProviderException
- {
- this(new JcaPGPKeyConverter().setProvider(provider).getPGPPublicKey(algorithm, pubKey, time));
- }
-
- /**
- * @deprecated use JcaPGPKeyConverter.getPGPPublicKey()
- */
- public PGPPublicKey(
- int algorithm,
- PublicKey pubKey,
- Date time)
- throws PGPException
- {
- this(new JcaPGPKeyConverter().getPGPPublicKey(algorithm, pubKey, time));
- }
/**
* Create a PGP public key from a packet descriptor using the passed in fingerPrintCalculator to do calculate
@@ -413,37 +373,6 @@ public class PGPPublicKey
}
/**
- * Return the public key contained in the object.
- *
- * @param provider provider to construct the key for.
- * @return a JCE/JCA public key.
- * @throws PGPException if the key algorithm is not recognised.
- * @throws NoSuchProviderException if the provider cannot be found.
- * @deprecated use a JcaPGPKeyConverter
- */
- public PublicKey getKey(
- String provider)
- throws PGPException, NoSuchProviderException
- {
- return new JcaPGPKeyConverter().setProvider(provider).getPublicKey(this);
- }
-
- /**
- * Return the public key contained in the object.
- *
- * @param provider provider to construct the key for.
- * @return a JCE/JCA public key.
- * @throws PGPException if the key algorithm is not recognised.
- * @deprecated use a JcaPGPKeyConverter
- */
- public PublicKey getKey(
- Provider provider)
- throws PGPException
- {
- return new JcaPGPKeyConverter().setProvider(provider).getPublicKey(this);
- }
-
- /**
* Return any userIDs associated with the key.
*
* @return an iterator of Strings.
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java
index 8e541fea..1dde086b 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java
@@ -2,8 +2,6 @@ package org.bouncycastle.openpgp;
import java.io.EOFException;
import java.io.InputStream;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.InputStreamPacket;
@@ -12,7 +10,6 @@ import org.bouncycastle.bcpg.SymmetricEncIntegrityPacket;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.openpgp.operator.PGPDataDecryptor;
import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
-import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
import org.bouncycastle.util.io.TeeInputStream;
/**
@@ -73,56 +70,6 @@ public class PGPPublicKeyEncryptedData
}
/**
- * Return the decrypted data stream for the packet.
- *
- * @param privKey private key to use
- * @param provider provider to use for private key and symmetric key decryption.
- * @return InputStream
- * @throws PGPException
- * @throws NoSuchProviderException
- * @deprecated use method that takes a PublicKeyDataDecryptorFactory
- */
- public InputStream getDataStream(
- PGPPrivateKey privKey,
- String provider)
- throws PGPException, NoSuchProviderException
- {
- return getDataStream(privKey, provider, provider);
- }
-
- /**
- * Return the decrypted data stream for the packet.
- *
- * @param privKey private key to use.
- * @param asymProvider asymetric provider to use with private key.
- * @param provider provider to use for symmetric algorithm.
- * @return InputStream
- * @throws PGPException
- * @throws NoSuchProviderException
- * @deprecated use method that takes a PublicKeyDataDecryptorFactory
- */
- public InputStream getDataStream(
- PGPPrivateKey privKey,
- String asymProvider,
- String provider)
- throws PGPException, NoSuchProviderException
- {
- return getDataStream(privKey, PGPUtil.getProvider(asymProvider), PGPUtil.getProvider(provider));
- }
-
- /**
- * @deprecated use method that takes a PublicKeyDataDecryptorFactory
- */
- public InputStream getDataStream(
- PGPPrivateKey privKey,
- Provider asymProvider,
- Provider provider)
- throws PGPException
- {
- return getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(asymProvider).setContentProvider(provider).build(privKey));
- }
-
- /**
* Open an input stream which will provide the decrypted data protected by this object.
*
* @param dataDecryptorFactory decryptor factory to use to recover the session data and provide the stream.
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java
index e3e9c438..4ea779d7 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPUtil.java
@@ -6,10 +6,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
import java.security.SecureRandom;
-import java.security.Security;
import java.util.Date;
import org.bouncycastle.asn1.ASN1InputStream;
@@ -351,19 +348,6 @@ public class PGPUtil
return new ArmoredInputStream(in);
}
}
-
- static Provider getProvider(String providerName)
- throws NoSuchProviderException
- {
- Provider prov = Security.getProvider(providerName);
-
- if (prov == null)
- {
- throw new NoSuchProviderException("provider " + providerName + " not found.");
- }
-
- return prov;
- }
static class BufferedInputStreamExt extends BufferedInputStream
{
diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPKeyRingTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPKeyRingTest.java
index f58cd4c4..e2b4ddbb 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPKeyRingTest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPKeyRingTest.java
@@ -9,6 +9,7 @@ import java.security.Security;
import java.util.Date;
import java.util.Iterator;
+import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ElGamalParameterSpec;
import org.bouncycastle.openpgp.PGPEncryptedData;
@@ -25,11 +26,15 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureList;
+import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider;
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.util.test.SimpleTest;
@@ -1936,9 +1941,10 @@ public class BcPGPKeyRingTest
KeyPair elgKp = elgKpg.generateKeyPair();
PGPKeyPair dsaKeyPair = new JcaPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
PGPKeyPair elgKeyPair = new JcaPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
-
+
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
- "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
keyRingGen.addSubKey(elgKeyPair);
@@ -1998,13 +2004,13 @@ public class BcPGPKeyRingTest
PGPKeyPair rsaKeyPair1 = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
rsaKp = rsaKpg.generateKeyPair();
PGPKeyPair rsaKeyPair2 = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
-
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
- "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
PGPSecretKeyRing secRing1 = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing1 = keyRingGen.generatePublicKeyRing();
keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair2,
- "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
PGPSecretKeyRing secRing2 = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing2 = keyRingGen.generatePublicKeyRing();
@@ -2063,9 +2069,10 @@ public class BcPGPKeyRingTest
KeyPair elgKp = elgKpg.generateKeyPair();
PGPKeyPair dsaKeyPair = new JcaPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
PGPKeyPair elgKeyPair = new JcaPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
-
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
- "test", PGPEncryptedData.AES_256, passPhrase, true, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
+
keyRingGen.addSubKey(elgKeyPair);
@@ -2212,9 +2219,9 @@ public class BcPGPKeyRingTest
rsaKp = rsaKpg.generateKeyPair();
PGPKeyPair rsaKeyPair2 = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
char[] passPhrase = "passwd".toCharArray();
-
- PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
- userID, PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
+ PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
+ userID, sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
PGPPublicKeyRing pubRing1 = keyRingGen.generatePublicKeyRing();
diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPRSATest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPRSATest.java
index 1b501c17..076e63d0 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPRSATest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/BcPGPRSATest.java
@@ -750,7 +750,7 @@ public class BcPGPRSATest
//
PGPPublicKeyRing pgpPub = new PGPPublicKeyRing(testPubKey, new BcKeyFingerprintCalculator());
- pubKey = pgpPub.getPublicKey().getKey("BC");
+ pubKey = new JcaPGPKeyConverter().setProvider("BC").getPublicKey(pgpPub.getPublicKey());
Iterator it = pgpPub.getPublicKey().getUserIDs();
@@ -784,7 +784,7 @@ public class BcPGPRSATest
// Read the public key
//
PGPPublicKeyRing pgpPubV3 = new PGPPublicKeyRing(testPubKeyV3, new BcKeyFingerprintCalculator());
- PublicKey pubKeyV3 = pgpPub.getPublicKey().getKey("BC");
+ PublicKey pubKeyV3 = new JcaPGPKeyConverter().setProvider("BC").getPublicKey(pgpPub.getPublicKey());
//
// write a V3 public key
diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
index 23a84e30..c021c9b3 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
@@ -260,7 +260,7 @@ public class PGPDSAElGamalTest
if (pgpKey.getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT
|| pgpKey.getAlgorithm() == PGPPublicKey.ELGAMAL_GENERAL)
{
- pKey = pgpKey.getKey("BC");
+ pKey = new JcaPGPKeyConverter().setProvider("BC").getPublicKey(pgpKey);
pgpKeyID = pgpKey.getKeyID();
if (pgpKey.getBitStrength() != 1024)
{
@@ -526,7 +526,7 @@ public class PGPDSAElGamalTest
PGPPublicKey k = (PGPPublicKey)objF.nextObject();
- pKey = k.getKey("BC");
+ pKey = new JcaPGPKeyConverter().setProvider("BC").getPublicKey(k);
pgpKeyID = k.getKeyID();
if (k.getBitStrength() != 1024)
{
diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPKeyRingTest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPKeyRingTest.java
index c0bef3c8..f6520bb7 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPKeyRingTest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPKeyRingTest.java
@@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream;
import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
-import java.security.SecureRandom;
import java.security.Security;
import java.util.Date;
import java.util.Iterator;
@@ -27,8 +26,10 @@ import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPSignature;
+import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
@@ -2084,9 +2085,10 @@ public class PGPKeyRingTest
KeyPair elgKp = elgKpg.generateKeyPair();
PGPKeyPair dsaKeyPair = new JcaPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
PGPKeyPair elgKeyPair = new JcaPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
-
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
- "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
+
keyRingGen.addSubKey(elgKeyPair);
@@ -2146,13 +2148,13 @@ public class PGPKeyRingTest
PGPKeyPair rsaKeyPair1 = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
rsaKp = rsaKpg.generateKeyPair();
PGPKeyPair rsaKeyPair2 = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
-
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
- "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
PGPSecretKeyRing secRing1 = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing1 = keyRingGen.generatePublicKeyRing();
keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair2,
- "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
PGPSecretKeyRing secRing2 = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing2 = keyRingGen.generatePublicKeyRing();
@@ -2211,9 +2213,10 @@ public class PGPKeyRingTest
KeyPair elgKp = elgKpg.generateKeyPair();
PGPKeyPair dsaKeyPair = new JcaPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
PGPKeyPair elgKeyPair = new JcaPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
-
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
- "test", PGPEncryptedData.AES_256, passPhrase, true, null, null, new SecureRandom(), "BC");
+ "test", sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
+
keyRingGen.addSubKey(elgKeyPair);
@@ -2536,9 +2539,10 @@ public class PGPKeyRingTest
rsaKp = rsaKpg.generateKeyPair();
PGPKeyPair rsaKeyPair2 = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, rsaKp, new Date());
char[] passPhrase = "passwd".toCharArray();
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
+ PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
+ userID, sha1Calc, null, null, new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
- PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsaKeyPair1,
- userID, PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");
PGPPublicKeyRing pubRing1 = keyRingGen.generatePublicKeyRing();
diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java
index cfb6c2f6..5e6460ad 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java
@@ -661,9 +661,9 @@ public class PGPRSATest
svg.setKeyFlags(true, KeyFlags.CERTIFY_OTHER + KeyFlags.SIGN_DATA);
PGPSignatureSubpacketVector hashedPcks = svg.generate();
- PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION,
- sgnKeyPair, identity, PGPEncryptedData.AES_256, passPhrase,
- true, hashedPcks, unhashedPcks, new SecureRandom(), "BC");
+ PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
+ PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, sgnKeyPair,
+ identity, sha1Calc, hashedPcks, unhashedPcks, new JcaPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).setProvider("BC").build(passPhrase));
svg = new PGPSignatureSubpacketGenerator();
svg.setKeyExpirationTime(true, 86400L * 366 * 2);
@@ -845,7 +845,7 @@ public class PGPRSATest
//
PGPPublicKeyRing pgpPub = new PGPPublicKeyRing(testPubKey);
- pubKey = pgpPub.getPublicKey().getKey("BC");
+ pubKey = new JcaPGPKeyConverter().setProvider("BC").getPublicKey(pgpPub.getPublicKey());
Iterator it = pgpPub.getPublicKey().getUserIDs();
@@ -879,7 +879,7 @@ public class PGPRSATest
// Read the public key
//
PGPPublicKeyRing pgpPubV3 = new PGPPublicKeyRing(testPubKeyV3);
- PublicKey pubKeyV3 = pgpPub.getPublicKey().getKey("BC");
+ PublicKey pubKeyV3 = new JcaPGPKeyConverter().setProvider("BC").getPublicKey(pgpPub.getPublicKey());
//
// write a V3 public key