Home | History | Annotate | Download | only in util
      1 package org.bouncycastle.jcajce.util;
      2 
      3 import java.security.AlgorithmParameterGenerator;
      4 import java.security.AlgorithmParameters;
      5 import java.security.KeyFactory;
      6 import java.security.KeyPairGenerator;
      7 import java.security.MessageDigest;
      8 import java.security.NoSuchAlgorithmException;
      9 import java.security.NoSuchProviderException;
     10 import java.security.SecureRandom;
     11 import java.security.Signature;
     12 import java.security.cert.CertificateException;
     13 import java.security.cert.CertificateFactory;
     14 
     15 import javax.crypto.Cipher;
     16 import javax.crypto.KeyAgreement;
     17 import javax.crypto.KeyGenerator;
     18 import javax.crypto.Mac;
     19 import javax.crypto.NoSuchPaddingException;
     20 import javax.crypto.SecretKeyFactory;
     21 
     22 /**
     23  * {@link JcaJceHelper} that obtains all algorithms using a specific named provider.
     24  */
     25 public class NamedJcaJceHelper
     26     implements JcaJceHelper
     27 {
     28     protected final String providerName;
     29 
     30     public NamedJcaJceHelper(String providerName)
     31     {
     32         this.providerName = providerName;
     33     }
     34 
     35     public Cipher createCipher(
     36         String algorithm)
     37         throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException
     38     {
     39         return Cipher.getInstance(algorithm, providerName);
     40     }
     41 
     42     public Mac createMac(String algorithm)
     43         throws NoSuchAlgorithmException, NoSuchProviderException
     44     {
     45         return Mac.getInstance(algorithm, providerName);
     46     }
     47 
     48     public KeyAgreement createKeyAgreement(String algorithm)
     49         throws NoSuchAlgorithmException, NoSuchProviderException
     50     {
     51         return KeyAgreement.getInstance(algorithm, providerName);
     52     }
     53 
     54     public AlgorithmParameterGenerator createAlgorithmParameterGenerator(String algorithm)
     55         throws NoSuchAlgorithmException, NoSuchProviderException
     56     {
     57         return AlgorithmParameterGenerator.getInstance(algorithm, providerName);
     58     }
     59 
     60     public AlgorithmParameters createAlgorithmParameters(String algorithm)
     61         throws NoSuchAlgorithmException, NoSuchProviderException
     62     {
     63         return AlgorithmParameters.getInstance(algorithm, providerName);
     64     }
     65 
     66     public KeyGenerator createKeyGenerator(String algorithm)
     67         throws NoSuchAlgorithmException, NoSuchProviderException
     68     {
     69         return KeyGenerator.getInstance(algorithm, providerName);
     70     }
     71 
     72     public KeyFactory createKeyFactory(String algorithm)
     73         throws NoSuchAlgorithmException, NoSuchProviderException
     74     {
     75         return KeyFactory.getInstance(algorithm, providerName);
     76     }
     77 
     78     public SecretKeyFactory createSecretKeyFactory(String algorithm)
     79         throws NoSuchAlgorithmException, NoSuchProviderException
     80     {
     81         return SecretKeyFactory.getInstance(algorithm, providerName);
     82     }
     83 
     84     public KeyPairGenerator createKeyPairGenerator(String algorithm)
     85         throws NoSuchAlgorithmException, NoSuchProviderException
     86     {
     87         return KeyPairGenerator.getInstance(algorithm, providerName);
     88     }
     89 
     90     public MessageDigest createDigest(String algorithm)
     91         throws NoSuchAlgorithmException, NoSuchProviderException
     92     {
     93         return MessageDigest.getInstance(algorithm, providerName);
     94     }
     95 
     96     public Signature createSignature(String algorithm)
     97         throws NoSuchAlgorithmException, NoSuchProviderException
     98     {
     99         return Signature.getInstance(algorithm, providerName);
    100     }
    101 
    102     public CertificateFactory createCertificateFactory(String algorithm)
    103         throws CertificateException, NoSuchProviderException
    104     {
    105         return CertificateFactory.getInstance(algorithm, providerName);
    106     }
    107 
    108     public SecureRandom createSecureRandom(String algorithm)
    109         throws NoSuchAlgorithmException, NoSuchProviderException
    110     {
    111         return SecureRandom.getInstance(algorithm, providerName);
    112     }
    113 }
    114