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