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.Provider; 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 from a specific {@link Provider} instance. 24 */ 25 public class ProviderJcaJceHelper 26 implements JcaJceHelper 27 { 28 protected final Provider provider; 29 30 public ProviderJcaJceHelper(Provider provider) 31 { 32 this.provider = provider; 33 } 34 35 public Cipher createCipher( 36 String algorithm) 37 throws NoSuchAlgorithmException, NoSuchPaddingException 38 { 39 return Cipher.getInstance(algorithm, provider); 40 } 41 42 public Mac createMac(String algorithm) 43 throws NoSuchAlgorithmException 44 { 45 return Mac.getInstance(algorithm, provider); 46 } 47 48 public KeyAgreement createKeyAgreement(String algorithm) 49 throws NoSuchAlgorithmException 50 { 51 return KeyAgreement.getInstance(algorithm, provider); 52 } 53 54 public AlgorithmParameterGenerator createAlgorithmParameterGenerator(String algorithm) 55 throws NoSuchAlgorithmException 56 { 57 return AlgorithmParameterGenerator.getInstance(algorithm, provider); 58 } 59 60 public AlgorithmParameters createAlgorithmParameters(String algorithm) 61 throws NoSuchAlgorithmException 62 { 63 return AlgorithmParameters.getInstance(algorithm, provider); 64 } 65 66 public KeyGenerator createKeyGenerator(String algorithm) 67 throws NoSuchAlgorithmException 68 { 69 return KeyGenerator.getInstance(algorithm, provider); 70 } 71 72 public KeyFactory createKeyFactory(String algorithm) 73 throws NoSuchAlgorithmException 74 { 75 return KeyFactory.getInstance(algorithm, provider); 76 } 77 78 public SecretKeyFactory createSecretKeyFactory(String algorithm) 79 throws NoSuchAlgorithmException 80 { 81 return SecretKeyFactory.getInstance(algorithm, provider); 82 } 83 84 public KeyPairGenerator createKeyPairGenerator(String algorithm) 85 throws NoSuchAlgorithmException 86 { 87 return KeyPairGenerator.getInstance(algorithm, provider); 88 } 89 90 public MessageDigest createDigest(String algorithm) 91 throws NoSuchAlgorithmException 92 { 93 return MessageDigest.getInstance(algorithm, provider); 94 } 95 96 public Signature createSignature(String algorithm) 97 throws NoSuchAlgorithmException 98 { 99 return Signature.getInstance(algorithm, provider); 100 } 101 102 public CertificateFactory createCertificateFactory(String algorithm) 103 throws CertificateException 104 { 105 return CertificateFactory.getInstance(algorithm, provider); 106 } 107 108 public SecureRandom createSecureRandom(String algorithm) 109 throws NoSuchAlgorithmException 110 { 111 return SecureRandom.getInstance(algorithm, provider); 112 } 113 } 114