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
path: root/pg
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2014-03-30 04:45:40 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-03-30 04:45:40 +0400
commit04b286bffca2cb6216e4a4ba68a3484ad1709308 (patch)
tree9ee230b24a69d46a80beafd82d80cf2e438c71af /pg
parent747a3c99ecda1a99955c86b8f045b6459793f2a8 (diff)
deprecated method removal.
added some additional deprecations. removed core selector dependency on crypto version of SHA-1
Diffstat (limited to 'pg')
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataGenerator.java199
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPPBEEncryptedData.java39
-rw-r--r--pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java42
-rw-r--r--pg/src/main/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java11
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java19
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/PGPPBETest.java44
-rw-r--r--pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java33
-rw-r--r--pg/src/test/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java11
8 files changed, 78 insertions, 320 deletions
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataGenerator.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataGenerator.java
index 24d35603..6ae92d13 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataGenerator.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataGenerator.java
@@ -2,8 +2,6 @@ package org.bouncycastle.openpgp;
import java.io.IOException;
import java.io.OutputStream;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
@@ -12,16 +10,11 @@ import org.bouncycastle.bcpg.BCPGOutputStream;
import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.bcpg.PacketTags;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator;
import org.bouncycastle.openpgp.operator.PGPDataEncryptor;
import org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder;
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator;
-import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
-import org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator;
-import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
-import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
import org.bouncycastle.util.io.TeeOutputStream;
/**
@@ -66,130 +59,22 @@ public class PGPEncryptedDataGenerator
private int defAlgorithm;
private SecureRandom rand;
- private static Provider defProvider;
-
- /**
- * Base constructor.
- *
- * @param encAlgorithm the symmetric algorithm to use.
- * @param rand source of randomness
- * @param provider the provider name to use for encryption algorithms.
- * @deprecated use constructor that takes a PGPDataEncryptor
- */
- public PGPEncryptedDataGenerator(
- int encAlgorithm,
- SecureRandom rand,
- String provider)
- {
- this(new JcePGPDataEncryptorBuilder(encAlgorithm).setSecureRandom(rand).setProvider(provider));
- }
-
- /**
- * Base constructor.
- *
- * @param encAlgorithm the symmetric algorithm to use.
- * @param rand source of randomness
- * @param provider the provider to use for encryption algorithms.
- * @deprecated use constructor that takes a PGPDataEncryptorBuilder
- */
- public PGPEncryptedDataGenerator(
- int encAlgorithm,
- SecureRandom rand,
- Provider provider)
- {
- this(new JcePGPDataEncryptorBuilder(encAlgorithm).setSecureRandom(rand).setProvider(provider));
- }
-
/**
- * Creates a cipher stream which will have an integrity packet
- * associated with it.
- *
- * @param encAlgorithm
- * @param withIntegrityPacket
- * @param rand
- * @param provider
- * @deprecated use constructor that takes a PGPDataEncryptorBuilder
- */
- public PGPEncryptedDataGenerator(
- int encAlgorithm,
- boolean withIntegrityPacket,
- SecureRandom rand,
- String provider)
- {
- this(new JcePGPDataEncryptorBuilder(encAlgorithm).setWithIntegrityPacket(withIntegrityPacket).setSecureRandom(rand).setProvider(provider));
- }
-
- /**
- * Creates a cipher stream which will have an integrity packet
- * associated with it.
- *
- * @param encAlgorithm
- * @param withIntegrityPacket
- * @param rand
- * @param provider
- * @deprecated use constructor that takes a PGPDataEncryptorBuilder
- */
- public PGPEncryptedDataGenerator(
- int encAlgorithm,
- boolean withIntegrityPacket,
- SecureRandom rand,
- Provider provider)
- {
- this(new JcePGPDataEncryptorBuilder(encAlgorithm).setWithIntegrityPacket(withIntegrityPacket).setSecureRandom(rand).setProvider(provider));
- }
-
- /**
- * Base constructor.
- *
- * @param encAlgorithm the symmetric algorithm to use.
- * @param rand source of randomness
- * @param oldFormat PGP 2.6.x compatibility required.
- * @param provider the provider to use for encryption algorithms.
- * @deprecated use constructor that takes a PGPDataEncryptorBuilder
- */
- public PGPEncryptedDataGenerator(
- int encAlgorithm,
- SecureRandom rand,
- boolean oldFormat,
- String provider)
- {
- this(new JcePGPDataEncryptorBuilder(encAlgorithm).setSecureRandom(rand).setProvider(provider), oldFormat);
- }
-
- /**
- * Base constructor.
- *
- * @param encAlgorithm the symmetric algorithm to use.
- * @param rand source of randomness
- * @param oldFormat PGP 2.6.x compatibility required.
- * @param provider the provider to use for encryption algorithms.
- * @deprecated use constructor that takes a PGPDataEncryptorBuilder
- */
- public PGPEncryptedDataGenerator(
- int encAlgorithm,
- SecureRandom rand,
- boolean oldFormat,
- Provider provider)
- {
- this(new JcePGPDataEncryptorBuilder(encAlgorithm).setSecureRandom(rand).setProvider(provider), oldFormat);
- }
-
- /**
- * Base constructor.
- *
- * @param encryptorBuilder builder to create actual data encryptor.
- */
+ * Base constructor.
+ *
+ * @param encryptorBuilder builder to create actual data encryptor.
+ */
public PGPEncryptedDataGenerator(PGPDataEncryptorBuilder encryptorBuilder)
{
this(encryptorBuilder, false);
}
- /**
- * Base constructor with the option to turn on formatting for PGP 2.6.x compatibility.
- *
- * @param encryptorBuilder builder to create actual data encryptor.
- * @param oldFormat PGP 2.6.x compatibility required.
- */
+ /**
+ * Base constructor with the option to turn on formatting for PGP 2.6.x compatibility.
+ *
+ * @param encryptorBuilder builder to create actual data encryptor.
+ * @param oldFormat PGP 2.6.x compatibility required.
+ */
public PGPEncryptedDataGenerator(PGPDataEncryptorBuilder encryptorBuilder, boolean oldFormat)
{
this.dataEncryptorBuilder = encryptorBuilder;
@@ -200,68 +85,6 @@ public class PGPEncryptedDataGenerator
}
/**
- * Add a PBE encryption method to the encrypted object using the default algorithm (S2K_SHA1).
- *
- * @param passPhrase
- * @throws NoSuchProviderException
- * @throws PGPException
- * @deprecated use addMethod that takes PGPKeyEncryptionMethodGenerator
- */
- public void addMethod(
- char[] passPhrase)
- throws NoSuchProviderException, PGPException
- {
- addMethod(passPhrase, HashAlgorithmTags.SHA1);
- }
-
- /**
- * Add a PBE encryption method to the encrypted object.
- *
- * @param passPhrase passphrase to use to generate key.
- * @param s2kDigest digest algorithm to use for S2K calculation
- * @throws NoSuchProviderException
- * @throws PGPException
- * @deprecated use addMethod that takes PGPKeyEncryptionMethodGenerator
- */
- public void addMethod(
- char[] passPhrase,
- int s2kDigest)
- throws NoSuchProviderException, PGPException
- {
- if (defProvider == null)
- {
- defProvider = new BouncyCastleProvider();
- }
-
- addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase, new JcaPGPDigestCalculatorProviderBuilder().setProvider(defProvider).build().get(s2kDigest)).setProvider(defProvider).setSecureRandom(rand));
- }
-
- /**
- * Add a public key encrypted session key to the encrypted object.
- *
- * @param key
- * @throws NoSuchProviderException
- * @throws PGPException
- * @deprecated use addMethod that takes PGPKeyEncryptionMethodGenerator
- */
- public void addMethod(
- PGPPublicKey key)
- throws NoSuchProviderException, PGPException
- {
- if (!key.isEncryptionKey())
- {
- throw new IllegalArgumentException("passed in key not an encryption key!");
- }
-
- if (defProvider == null)
- {
- defProvider = new BouncyCastleProvider();
- }
-
- addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key).setProvider(defProvider).setSecureRandom(rand));
- }
-
- /**
* Added a key encryption method to be used to encrypt the session data associated
* with this encrypted data.
*
@@ -308,7 +131,7 @@ public class PGPEncryptedDataGenerator
* @param out
* @param length
* @param buffer
- * @return
+ * @return the generator's output stream.
* @throws java.io.IOException
* @throws PGPException
* @throws IllegalStateException
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPPBEEncryptedData.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPPBEEncryptedData.java
index c3143395..a24cdc47 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPPBEEncryptedData.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPPBEEncryptedData.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;
@@ -11,8 +9,6 @@ import org.bouncycastle.bcpg.SymmetricEncIntegrityPacket;
import org.bouncycastle.bcpg.SymmetricKeyEncSessionPacket;
import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
import org.bouncycastle.openpgp.operator.PGPDataDecryptor;
-import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
-import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
import org.bouncycastle.util.io.TeeInputStream;
/**
@@ -42,41 +38,6 @@ public class PGPPBEEncryptedData
return encData.getInputStream();
}
- /**
- * Return the decrypted input stream, using the passed in passPhrase.
- *
- * @param passPhrase
- * @param provider
- * @return InputStream
- * @throws PGPException
- * @throws NoSuchProviderException
- * @deprecated use PBEDataDecryptorFactory method
- */
- public InputStream getDataStream(
- char[] passPhrase,
- String provider)
- throws PGPException, NoSuchProviderException
- {
- return getDataStream(passPhrase, PGPUtil.getProvider(provider));
- }
-
- /**
- * Return the decrypted input stream, using the passed in passPhrase.
- *
- * @param passPhrase
- * @param provider
- * @return InputStream
- * @throws PGPException
- * @deprecated use PBEDataDecryptorFactory method
- */
- public InputStream getDataStream(
- char[] passPhrase,
- Provider provider)
- throws PGPException
- {
- return getDataStream(new JcePBEDataDecryptorFactoryBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider(provider).build()).setProvider(provider).build(passPhrase));
- }
-
/**
* Return the symmetric key algorithm required to decrypt the data protected by this object.
*
diff --git a/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java b/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java
index 27747c06..8e541fea 100644
--- a/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java
+++ b/pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKeyEncryptedData.java
@@ -57,32 +57,6 @@ public class PGPPublicKeyEncryptedData
}
/**
- * Return the algorithm code for the symmetric algorithm used to encrypt the data.
- *
- * @return integer algorithm code
- * @deprecated use the method taking a PublicKeyDataDecryptorFactory
- */
- public int getSymmetricAlgorithm(
- PGPPrivateKey privKey,
- String provider)
- throws PGPException, NoSuchProviderException
- {
- return getSymmetricAlgorithm(privKey, PGPUtil.getProvider(provider));
- }
-
- /**
- *
- * @deprecated use the method taking a PublicKeyDataDecryptorFactory
- */
- public int getSymmetricAlgorithm(
- PGPPrivateKey privKey,
- Provider provider)
- throws PGPException, NoSuchProviderException
- {
- return getSymmetricAlgorithm(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(provider).setContentProvider(provider).build(privKey));
- }
-
- /**
* Return the symmetric key algorithm required to decrypt the data protected by this object.
*
* @param dataDecryptorFactory decryptor factory to use to recover the session data.
@@ -116,22 +90,6 @@ public class PGPPublicKeyEncryptedData
return getDataStream(privKey, provider, provider);
}
- /**
- *
- * @param privKey
- * @param provider
- * @return
- * @throws PGPException
- * @deprecated use method that takes a PublicKeyDataDecryptorFactory
- */
- public InputStream getDataStream(
- PGPPrivateKey privKey,
- Provider provider)
- throws PGPException
- {
- return getDataStream(privKey, provider, provider);
- }
-
/**
* Return the decrypted data stream for the packet.
*
diff --git a/pg/src/main/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java b/pg/src/main/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
index 251d4348..11f9670d 100644
--- a/pg/src/main/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
+++ b/pg/src/main/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
@@ -22,6 +22,7 @@ import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ElGamalParameterSpec;
import org.bouncycastle.openpgp.PGPCompressedData;
+import org.bouncycastle.openpgp.PGPEncryptedData;
import org.bouncycastle.openpgp.PGPEncryptedDataGenerator;
import org.bouncycastle.openpgp.PGPEncryptedDataList;
import org.bouncycastle.openpgp.PGPKeyPair;
@@ -294,7 +295,7 @@ public class PGPDSAElGamalTest implements Test
PGPPublicKeyEncryptedData encP = (PGPPublicKeyEncryptedData)encList.get(0);
- InputStream clear = encP.getDataStream(pgpPrivKey, "BC");
+ InputStream clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
pgpFact = new PGPObjectFactory(clear);
@@ -332,7 +333,7 @@ public class PGPDSAElGamalTest implements Test
encP = (PGPPublicKeyEncryptedData)encList.get(0);
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
pgpFact = new PGPObjectFactory(clear);
@@ -382,10 +383,10 @@ public class PGPDSAElGamalTest implements Test
// encrypt
//
ByteArrayOutputStream cbOut = new ByteArrayOutputStream();
- PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.TRIPLE_DES, new SecureRandom(), "BC");
+ PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.TRIPLE_DES).setSecureRandom(new SecureRandom()).setProvider("BC"));
PGPPublicKey puK = sKey.getSecretKey(pgpKeyID).getPublicKey();
- cPk.addMethod(puK);
+ cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(puK).setProvider("BC"));
OutputStream cOut = cPk.open(cbOut, bOut.toByteArray().length);
@@ -401,7 +402,7 @@ public class PGPDSAElGamalTest implements Test
pgpPrivKey = sKey.getSecretKey(pgpKeyID).extractPrivateKey(pass, "BC");
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
bOut.reset();
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 76ff2708..04474cff 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
@@ -43,6 +43,9 @@ import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureGenerator;
import org.bouncycastle.openpgp.PGPSignatureList;
import org.bouncycastle.openpgp.PGPUtil;
+import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.test.SimpleTest;
import org.bouncycastle.util.test.UncloseableOutputStream;
@@ -294,7 +297,7 @@ public class PGPDSAElGamalTest
PGPPublicKeyEncryptedData encP = (PGPPublicKeyEncryptedData)encList.get(0);
- InputStream clear = encP.getDataStream(pgpPrivKey, "BC");
+ InputStream clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
pgpFact = new PGPObjectFactory(clear);
@@ -332,7 +335,7 @@ public class PGPDSAElGamalTest
encP = (PGPPublicKeyEncryptedData)encList.get(0);
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
pgpFact = new PGPObjectFactory(clear);
@@ -382,10 +385,10 @@ public class PGPDSAElGamalTest
// encrypt
//
ByteArrayOutputStream cbOut = new ByteArrayOutputStream();
- PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.TRIPLE_DES, new SecureRandom(), "BC");
+ PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.TRIPLE_DES).setSecureRandom(new SecureRandom()).setProvider("BC"));
PGPPublicKey puK = sKey.getSecretKey(pgpKeyID).getPublicKey();
- cPk.addMethod(puK);
+ cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(puK).setProvider("BC"));
OutputStream cOut = cPk.open(new UncloseableOutputStream(cbOut), bOut.toByteArray().length);
@@ -401,7 +404,7 @@ public class PGPDSAElGamalTest
pgpPrivKey = sKey.getSecretKey(pgpKeyID).extractPrivateKey(pass, "BC");
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
bOut.reset();
@@ -460,11 +463,11 @@ public class PGPDSAElGamalTest
PGPKeyPair elGamalKeyPair = new PGPKeyPair(
PublicKeyAlgorithmTags.ELGAMAL_GENERAL, kp, new Date());
- cPk = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.CAST5, random, "BC");
+ cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5).setSecureRandom(new SecureRandom()).setProvider("BC"));
puK = elGamalKeyPair.getPublicKey();
- cPk.addMethod(puK);
+ cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(puK).setProvider("BC"));
cbOut = new ByteArrayOutputStream();
@@ -483,7 +486,7 @@ public class PGPDSAElGamalTest
pgpPrivKey = elGamalKeyPair.getPrivateKey();
// Note: This is where an exception would be expected if the P size causes problems
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
ByteArrayOutputStream dec = new ByteArrayOutputStream();
diff --git a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPPBETest.java b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPPBETest.java
index 0aa6570f..f65be934 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPPBETest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPPBETest.java
@@ -1,5 +1,12 @@
package org.bouncycastle.openpgp.test;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.util.Date;
+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openpgp.PGPCompressedData;
import org.bouncycastle.openpgp.PGPCompressedDataGenerator;
@@ -10,18 +17,15 @@ import org.bouncycastle.openpgp.PGPLiteralData;
import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
import org.bouncycastle.openpgp.PGPObjectFactory;
import org.bouncycastle.openpgp.PGPPBEEncryptedData;
+import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator;
+import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.util.test.SimpleTest;
import org.bouncycastle.util.test.UncloseableOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.security.SecureRandom;
-import java.security.Security;
-import java.util.Date;
-
public class PGPPBETest
extends SimpleTest
{
@@ -66,7 +70,7 @@ public class PGPPBETest
PGPEncryptedDataList enc = (PGPEncryptedDataList)pgpF.nextObject();
PGPPBEEncryptedData pbe = (PGPPBEEncryptedData)enc.get(0);
- InputStream clear = pbe.getDataStream(pass, "BC");
+ InputStream clear = pbe.getDataStream(new JcePBEDataDecryptorFactoryBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider("BC").build()).setProvider("BC").build(pass));
PGPObjectFactory pgpFact = new PGPObjectFactory(clear);
PGPCompressedData cData = (PGPCompressedData)pgpFact.nextObject();
@@ -111,7 +115,7 @@ public class PGPPBETest
PGPEncryptedDataList enc = (PGPEncryptedDataList)pgpF.nextObject();
PGPPBEEncryptedData pbe = (PGPPBEEncryptedData)enc.get(0);
- InputStream clear = pbe.getDataStream(pass, "BC");
+ InputStream clear = pbe.getDataStream(new JcePBEDataDecryptorFactoryBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider("BC").build()).setProvider("BC").build(pass));
PGPObjectFactory pgpFact = new PGPObjectFactory(clear);
PGPCompressedData cData = (PGPCompressedData)pgpFact.nextObject();
@@ -191,9 +195,9 @@ public class PGPPBETest
// encrypt - with stream close
//
ByteArrayOutputStream cbOut = new ByteArrayOutputStream();
- PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, new SecureRandom(), "BC");
+ PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setSecureRandom(new SecureRandom()).setProvider("BC"));
- cPk.addMethod(pass);
+ cPk.addMethod(new JcePBEKeyEncryptionMethodGenerator(pass).setProvider("BC"));
OutputStream cOut = cPk.open(new UncloseableOutputStream(cbOut), bOut.toByteArray().length);
@@ -212,9 +216,9 @@ public class PGPPBETest
// encrypt - with generator close
//
cbOut = new ByteArrayOutputStream();
- cPk = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, new SecureRandom(), "BC");
+ cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setSecureRandom(new SecureRandom()).setProvider("BC"));
- cPk.addMethod(pass);
+ cPk.addMethod(new JcePBEKeyEncryptionMethodGenerator(pass).setProvider("BC"));
cOut = cPk.open(new UncloseableOutputStream(cbOut), bOut.toByteArray().length);
@@ -256,9 +260,9 @@ public class PGPPBETest
comOut.close();
cbOut = new ByteArrayOutputStream();
- cPk = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, rand, "BC");
+ cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setSecureRandom(rand).setProvider("BC"));
- cPk.addMethod(pass);
+ cPk.addMethod(new JcePBEKeyEncryptionMethodGenerator(pass).setProvider("BC"));
cOut = cPk.open(new UncloseableOutputStream(cbOut), new byte[16]);
@@ -276,9 +280,9 @@ public class PGPPBETest
// with integrity packet
//
cbOut = new ByteArrayOutputStream();
- cPk = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, true, rand, "BC");
+ cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(true).setSecureRandom(rand).setProvider("BC"));
- cPk.addMethod(pass);
+ cPk.addMethod(new JcePBEKeyEncryptionMethodGenerator(pass).setProvider("BC"));
cOut = cPk.open(new UncloseableOutputStream(cbOut), new byte[16]);
@@ -310,7 +314,7 @@ public class PGPPBETest
PGPPBEEncryptedData pbe = (PGPPBEEncryptedData)enc.get(1);
- InputStream clear = pbe.getDataStream("password".toCharArray(), "BC");
+ InputStream clear = pbe.getDataStream(new JcePBEDataDecryptorFactoryBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider("BC").build()).setProvider("BC").build("password".toCharArray()));
pgpFact = new PGPObjectFactory(clear);
@@ -355,9 +359,9 @@ public class PGPPBETest
comOut.close();
cbOut = new ByteArrayOutputStream();
- cPk = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, true, rand, "BC");
+ cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(true).setSecureRandom(rand).setProvider("BC"));
- cPk.addMethod(pass);
+ cPk.addMethod(new JcePBEKeyEncryptionMethodGenerator(pass).setProvider("BC"));
cOut = cPk.open(new UncloseableOutputStream(cbOut), new byte[16]);
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 41fa6c10..485a344a 100644
--- a/pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java
+++ b/pg/src/test/java/org/bouncycastle/openpgp/test/PGPRSATest.java
@@ -53,11 +53,17 @@ import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.PGPV3SignatureGenerator;
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
+import org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory;
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
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.JcePBEDataDecryptorFactoryBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator;
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
+import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.encoders.Hex;
@@ -436,11 +442,11 @@ public class PGPRSATest
ByteArrayOutputStream bcOut = new ByteArrayOutputStream();
- PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.AES_128, true, new SecureRandom(), "BC");
+ PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.AES_128).setWithIntegrityPacket(true).setSecureRandom(new SecureRandom()).setProvider("BC"));
- encGen.addMethod(pgpPubKey);
+ encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(pgpPubKey).setProvider("BC"));
- encGen.addMethod("password".toCharArray());
+ encGen.addMethod(new JcePBEKeyEncryptionMethodGenerator("password".toCharArray()).setProvider("BC"));
OutputStream cOut = encGen.open(bcOut, bytes.length);
@@ -459,7 +465,7 @@ public class PGPRSATest
PGPPublicKeyEncryptedData encP = (PGPPublicKeyEncryptedData)encList.get(0);
- InputStream clear = encP.getDataStream(pgpPrivKey, "BC");
+ InputStream clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
PGPObjectFactory pgpFact = new PGPObjectFactory(clear);
@@ -474,7 +480,7 @@ public class PGPRSATest
PGPPBEEncryptedData encPbe = (PGPPBEEncryptedData)encList.get(1);
- clear = encPbe.getDataStream("password".toCharArray(), "BC");
+ clear = encPbe.getDataStream(new JcePBEDataDecryptorFactoryBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider("BC").build()).setProvider("BC").build("password".toCharArray()));
pgpF = new PGPObjectFactory(clear);
@@ -994,7 +1000,7 @@ public class PGPRSATest
pgpPrivKey = pgpPriv.getSecretKey(encP.getKeyID()).extractPrivateKey(pass, "BC");
- InputStream clear = encP.getDataStream(pgpPrivKey, "BC");
+ InputStream clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
pgpFact = new PGPObjectFactory(clear);
@@ -1029,10 +1035,10 @@ public class PGPRSATest
byte[] shortText = { (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o' };
ByteArrayOutputStream cbOut = new ByteArrayOutputStream();
- PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.CAST5, new SecureRandom(), "BC");
+ PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5).setSecureRandom(new SecureRandom()).setProvider("BC"));
PGPPublicKey puK = pgpPriv.getSecretKey(encP.getKeyID()).getPublicKey();
- cPk.addMethod(puK);
+ cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(puK).setProvider("BC"));
OutputStream cOut = cPk.open(new UncloseableOutputStream(cbOut), shortText.length);
@@ -1048,12 +1054,13 @@ public class PGPRSATest
pgpPrivKey = pgpPriv.getSecretKey(encP.getKeyID()).extractPrivateKey(pass, "BC");
- if (encP.getSymmetricAlgorithm(pgpPrivKey, "BC") != SymmetricKeyAlgorithmTags.CAST5)
+ PublicKeyDataDecryptorFactory dataDecryptorFactory = new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey);
+ if (encP.getSymmetricAlgorithm(dataDecryptorFactory) != SymmetricKeyAlgorithmTags.CAST5)
{
fail("symmetric algorithm mismatch");
}
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(dataDecryptorFactory);
bOut.reset();
@@ -1073,10 +1080,10 @@ public class PGPRSATest
// encrypt
//
cbOut = new ByteArrayOutputStream();
- cPk = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.CAST5, new SecureRandom(), "BC");
+ cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.CAST5).setSecureRandom(new SecureRandom()).setProvider("BC"));
puK = pgpPriv.getSecretKey(encP.getKeyID()).getPublicKey();
- cPk.addMethod(puK);
+ cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(puK).setProvider("BC"));
cOut = cPk.open(new UncloseableOutputStream(cbOut), text.length);
@@ -1092,7 +1099,7 @@ public class PGPRSATest
pgpPrivKey = pgpPriv.getSecretKey(encP.getKeyID()).extractPrivateKey(pass, "BC");
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
bOut.reset();
diff --git a/pg/src/test/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java b/pg/src/test/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
index 251d4348..11f9670d 100644
--- a/pg/src/test/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
+++ b/pg/src/test/jdk1.1/org/bouncycastle/openpgp/test/PGPDSAElGamalTest.java
@@ -22,6 +22,7 @@ import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ElGamalParameterSpec;
import org.bouncycastle.openpgp.PGPCompressedData;
+import org.bouncycastle.openpgp.PGPEncryptedData;
import org.bouncycastle.openpgp.PGPEncryptedDataGenerator;
import org.bouncycastle.openpgp.PGPEncryptedDataList;
import org.bouncycastle.openpgp.PGPKeyPair;
@@ -294,7 +295,7 @@ public class PGPDSAElGamalTest implements Test
PGPPublicKeyEncryptedData encP = (PGPPublicKeyEncryptedData)encList.get(0);
- InputStream clear = encP.getDataStream(pgpPrivKey, "BC");
+ InputStream clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
pgpFact = new PGPObjectFactory(clear);
@@ -332,7 +333,7 @@ public class PGPDSAElGamalTest implements Test
encP = (PGPPublicKeyEncryptedData)encList.get(0);
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
pgpFact = new PGPObjectFactory(clear);
@@ -382,10 +383,10 @@ public class PGPDSAElGamalTest implements Test
// encrypt
//
ByteArrayOutputStream cbOut = new ByteArrayOutputStream();
- PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.TRIPLE_DES, new SecureRandom(), "BC");
+ PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.TRIPLE_DES).setSecureRandom(new SecureRandom()).setProvider("BC"));
PGPPublicKey puK = sKey.getSecretKey(pgpKeyID).getPublicKey();
- cPk.addMethod(puK);
+ cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(puK).setProvider("BC"));
OutputStream cOut = cPk.open(cbOut, bOut.toByteArray().length);
@@ -401,7 +402,7 @@ public class PGPDSAElGamalTest implements Test
pgpPrivKey = sKey.getSecretKey(pgpKeyID).extractPrivateKey(pass, "BC");
- clear = encP.getDataStream(pgpPrivKey, "BC");
+ clear = encP.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(pgpPrivKey));
bOut.reset();