diff options
Diffstat (limited to 'prov/src/main/java/org/bouncycastle/jcajce/util')
5 files changed, 0 insertions, 497 deletions
diff --git a/prov/src/main/java/org/bouncycastle/jcajce/util/DefaultJcaJceHelper.java b/prov/src/main/java/org/bouncycastle/jcajce/util/DefaultJcaJceHelper.java deleted file mode 100644 index 43a97f30..00000000 --- a/prov/src/main/java/org/bouncycastle/jcajce/util/DefaultJcaJceHelper.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.bouncycastle.jcajce.util; - -import java.security.AlgorithmParameterGenerator; -import java.security.AlgorithmParameters; -import java.security.KeyFactory; -import java.security.KeyPairGenerator; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.Signature; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; - -import javax.crypto.Cipher; -import javax.crypto.KeyAgreement; -import javax.crypto.KeyGenerator; -import javax.crypto.Mac; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKeyFactory; - -/** - * {@link JcaJceHelper} that obtains all algorithms using the default JCA/JCE mechanism (i.e. - * without specifying a provider). - */ -public class DefaultJcaJceHelper - implements JcaJceHelper -{ - public Cipher createCipher( - String algorithm) - throws NoSuchAlgorithmException, NoSuchPaddingException - { - return Cipher.getInstance(algorithm); - } - - public Mac createMac(String algorithm) - throws NoSuchAlgorithmException - { - return Mac.getInstance(algorithm); - } - - public KeyAgreement createKeyAgreement(String algorithm) - throws NoSuchAlgorithmException - { - return KeyAgreement.getInstance(algorithm); - } - - public AlgorithmParameterGenerator createAlgorithmParameterGenerator(String algorithm) - throws NoSuchAlgorithmException - { - return AlgorithmParameterGenerator.getInstance(algorithm); - } - - public AlgorithmParameters createAlgorithmParameters(String algorithm) - throws NoSuchAlgorithmException - { - return AlgorithmParameters.getInstance(algorithm); - } - - public KeyGenerator createKeyGenerator(String algorithm) - throws NoSuchAlgorithmException - { - return KeyGenerator.getInstance(algorithm); - } - - public KeyFactory createKeyFactory(String algorithm) - throws NoSuchAlgorithmException - { - return KeyFactory.getInstance(algorithm); - } - - public SecretKeyFactory createSecretKeyFactory(String algorithm) - throws NoSuchAlgorithmException - { - return SecretKeyFactory.getInstance(algorithm); - } - - public KeyPairGenerator createKeyPairGenerator(String algorithm) - throws NoSuchAlgorithmException - { - return KeyPairGenerator.getInstance(algorithm); - } - - public MessageDigest createDigest(String algorithm) - throws NoSuchAlgorithmException - { - return MessageDigest.getInstance(algorithm); - } - - public Signature createSignature(String algorithm) - throws NoSuchAlgorithmException - { - return Signature.getInstance(algorithm); - } - - public CertificateFactory createCertificateFactory(String algorithm) - throws NoSuchAlgorithmException, CertificateException - { - return CertificateFactory.getInstance(algorithm); - } -} diff --git a/prov/src/main/java/org/bouncycastle/jcajce/util/JcaJceHelper.java b/prov/src/main/java/org/bouncycastle/jcajce/util/JcaJceHelper.java deleted file mode 100644 index f5da3354..00000000 --- a/prov/src/main/java/org/bouncycastle/jcajce/util/JcaJceHelper.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.bouncycastle.jcajce.util; - -import java.security.AlgorithmParameterGenerator; -import java.security.AlgorithmParameters; -import java.security.KeyFactory; -import java.security.KeyPairGenerator; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Signature; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; - -import javax.crypto.Cipher; -import javax.crypto.KeyAgreement; -import javax.crypto.KeyGenerator; -import javax.crypto.Mac; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKeyFactory; - -/** - * Factory interface for instantiating JCA/JCE primitives. - */ -public interface JcaJceHelper -{ - Cipher createCipher( - String algorithm) - throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException; - - Mac createMac(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - KeyAgreement createKeyAgreement(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - AlgorithmParameterGenerator createAlgorithmParameterGenerator(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - AlgorithmParameters createAlgorithmParameters(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - KeyGenerator createKeyGenerator(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - KeyFactory createKeyFactory(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - SecretKeyFactory createSecretKeyFactory(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - KeyPairGenerator createKeyPairGenerator(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - MessageDigest createDigest(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - Signature createSignature(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException; - - CertificateFactory createCertificateFactory(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException, CertificateException; -} diff --git a/prov/src/main/java/org/bouncycastle/jcajce/util/JcaJceUtils.java b/prov/src/main/java/org/bouncycastle/jcajce/util/JcaJceUtils.java deleted file mode 100644 index 9f62ced8..00000000 --- a/prov/src/main/java/org/bouncycastle/jcajce/util/JcaJceUtils.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.bouncycastle.jcajce.util; - -import java.io.IOException; -import java.security.AlgorithmParameters; - -import org.bouncycastle.asn1.ASN1Encodable; -import org.bouncycastle.asn1.ASN1ObjectIdentifier; -import org.bouncycastle.asn1.ASN1Primitive; -import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; -import org.bouncycastle.asn1.nist.NISTObjectIdentifiers; -import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; -import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; -import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers; - -/** - * General JCA/JCE utility methods. - */ -public class JcaJceUtils -{ - private JcaJceUtils() - { - - } - - /** - * Extract an ASN.1 encodable from an AlgorithmParameters object. - * - * @param params the object to get the encoding used to create the return value. - * @return an ASN.1 object representing the primitives making up the params parameter. - * @throws IOException if an encoding cannot be extracted. - */ - public static ASN1Encodable extractParameters(AlgorithmParameters params) - throws IOException - { - // we try ASN.1 explicitly first just in case and then role back to the default. - ASN1Encodable asn1Params; - try - { - asn1Params = ASN1Primitive.fromByteArray(params.getEncoded("ASN.1")); - } - catch (Exception ex) - { - asn1Params = ASN1Primitive.fromByteArray(params.getEncoded()); - } - - return asn1Params; - } - - /** - * Load an AlgorithmParameters object with the passed in ASN.1 encodable - if possible. - * - * @param params the AlgorithmParameters object to be initialised. - * @param sParams the ASN.1 encodable to initialise params with. - * @throws IOException if the parameters cannot be initialised. - */ - public static void loadParameters(AlgorithmParameters params, ASN1Encodable sParams) - throws IOException - { - // we try ASN.1 explicitly first just in case and then role back to the default. - try - { - params.init(sParams.toASN1Primitive().getEncoded(), "ASN.1"); - } - catch (Exception ex) - { - params.init(sParams.toASN1Primitive().getEncoded()); - } - } - - /** - * Attempt to find a standard JCA name for the digest represented by the past in OID. - * - * @param digestAlgOID the OID of the digest algorithm of interest. - * @return a string representing the standard name - the OID as a string if none available. - */ - public static String getDigestAlgName( - ASN1ObjectIdentifier digestAlgOID) - { - if (PKCSObjectIdentifiers.md5.equals(digestAlgOID)) - { - return "MD5"; - } - else if (OIWObjectIdentifiers.idSHA1.equals(digestAlgOID)) - { - return "SHA1"; - } - else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOID)) - { - return "SHA224"; - } - else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOID)) - { - return "SHA256"; - } - else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOID)) - { - return "SHA384"; - } - else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOID)) - { - return "SHA512"; - } - else if (TeleTrusTObjectIdentifiers.ripemd128.equals(digestAlgOID)) - { - return "RIPEMD128"; - } - else if (TeleTrusTObjectIdentifiers.ripemd160.equals(digestAlgOID)) - { - return "RIPEMD160"; - } - else if (TeleTrusTObjectIdentifiers.ripemd256.equals(digestAlgOID)) - { - return "RIPEMD256"; - } - else if (CryptoProObjectIdentifiers.gostR3411.equals(digestAlgOID)) - { - return "GOST3411"; - } - else - { - return digestAlgOID.getId(); - } - } -} diff --git a/prov/src/main/java/org/bouncycastle/jcajce/util/NamedJcaJceHelper.java b/prov/src/main/java/org/bouncycastle/jcajce/util/NamedJcaJceHelper.java deleted file mode 100644 index ebbfacc1..00000000 --- a/prov/src/main/java/org/bouncycastle/jcajce/util/NamedJcaJceHelper.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.bouncycastle.jcajce.util; - -import java.security.AlgorithmParameterGenerator; -import java.security.AlgorithmParameters; -import java.security.KeyFactory; -import java.security.KeyPairGenerator; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Signature; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; - -import javax.crypto.Cipher; -import javax.crypto.KeyAgreement; -import javax.crypto.KeyGenerator; -import javax.crypto.Mac; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKeyFactory; - -/** - * {@link JcaJceHelper} that obtains all algorithms using a specific named provider. - */ -public class NamedJcaJceHelper - implements JcaJceHelper -{ - protected final String providerName; - - public NamedJcaJceHelper(String providerName) - { - this.providerName = providerName; - } - - public Cipher createCipher( - String algorithm) - throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException - { - return Cipher.getInstance(algorithm, providerName); - } - - public Mac createMac(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return Mac.getInstance(algorithm, providerName); - } - - public KeyAgreement createKeyAgreement(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return KeyAgreement.getInstance(algorithm, providerName); - } - - public AlgorithmParameterGenerator createAlgorithmParameterGenerator(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return AlgorithmParameterGenerator.getInstance(algorithm, providerName); - } - - public AlgorithmParameters createAlgorithmParameters(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return AlgorithmParameters.getInstance(algorithm, providerName); - } - - public KeyGenerator createKeyGenerator(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return KeyGenerator.getInstance(algorithm, providerName); - } - - public KeyFactory createKeyFactory(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return KeyFactory.getInstance(algorithm, providerName); - } - - public SecretKeyFactory createSecretKeyFactory(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return SecretKeyFactory.getInstance(algorithm, providerName); - } - - public KeyPairGenerator createKeyPairGenerator(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return KeyPairGenerator.getInstance(algorithm, providerName); - } - - public MessageDigest createDigest(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return MessageDigest.getInstance(algorithm, providerName); - } - - public Signature createSignature(String algorithm) - throws NoSuchAlgorithmException, NoSuchProviderException - { - return Signature.getInstance(algorithm, providerName); - } - - public CertificateFactory createCertificateFactory(String algorithm) - throws NoSuchAlgorithmException, CertificateException, NoSuchProviderException - { - return CertificateFactory.getInstance(algorithm, providerName); - } -} diff --git a/prov/src/main/java/org/bouncycastle/jcajce/util/ProviderJcaJceHelper.java b/prov/src/main/java/org/bouncycastle/jcajce/util/ProviderJcaJceHelper.java deleted file mode 100644 index fad10481..00000000 --- a/prov/src/main/java/org/bouncycastle/jcajce/util/ProviderJcaJceHelper.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.bouncycastle.jcajce.util; - -import java.security.AlgorithmParameterGenerator; -import java.security.AlgorithmParameters; -import java.security.KeyFactory; -import java.security.KeyPairGenerator; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.Provider; -import java.security.Signature; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; - -import javax.crypto.Cipher; -import javax.crypto.KeyAgreement; -import javax.crypto.KeyGenerator; -import javax.crypto.Mac; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKeyFactory; - -/** - * {@link JcaJceHelper} that obtains all algorithms from a specific {@link Provider} instance. - */ -public class ProviderJcaJceHelper - implements JcaJceHelper -{ - protected final Provider provider; - - public ProviderJcaJceHelper(Provider provider) - { - this.provider = provider; - } - - public Cipher createCipher( - String algorithm) - throws NoSuchAlgorithmException, NoSuchPaddingException - { - return Cipher.getInstance(algorithm, provider); - } - - public Mac createMac(String algorithm) - throws NoSuchAlgorithmException - { - return Mac.getInstance(algorithm, provider); - } - - public KeyAgreement createKeyAgreement(String algorithm) - throws NoSuchAlgorithmException - { - return KeyAgreement.getInstance(algorithm, provider); - } - - public AlgorithmParameterGenerator createAlgorithmParameterGenerator(String algorithm) - throws NoSuchAlgorithmException - { - return AlgorithmParameterGenerator.getInstance(algorithm, provider); - } - - public AlgorithmParameters createAlgorithmParameters(String algorithm) - throws NoSuchAlgorithmException - { - return AlgorithmParameters.getInstance(algorithm, provider); - } - - public KeyGenerator createKeyGenerator(String algorithm) - throws NoSuchAlgorithmException - { - return KeyGenerator.getInstance(algorithm, provider); - } - - public KeyFactory createKeyFactory(String algorithm) - throws NoSuchAlgorithmException - { - return KeyFactory.getInstance(algorithm, provider); - } - - public SecretKeyFactory createSecretKeyFactory(String algorithm) - throws NoSuchAlgorithmException - { - return SecretKeyFactory.getInstance(algorithm, provider); - } - - public KeyPairGenerator createKeyPairGenerator(String algorithm) - throws NoSuchAlgorithmException - { - return KeyPairGenerator.getInstance(algorithm, provider); - } - - public MessageDigest createDigest(String algorithm) - throws NoSuchAlgorithmException - { - return MessageDigest.getInstance(algorithm, provider); - } - - public Signature createSignature(String algorithm) - throws NoSuchAlgorithmException - { - return Signature.getInstance(algorithm, provider); - } - - public CertificateFactory createCertificateFactory(String algorithm) - throws NoSuchAlgorithmException, CertificateException - { - return CertificateFactory.getInstance(algorithm, provider); - } -} |