1 2 package java.security; 3 4 import java.io.IOException; 5 import java.security.spec.AlgorithmParameterSpec; 6 import java.security.spec.InvalidParameterSpecException; 7 8 public class AlgorithmParameters extends Object 9 { 10 private AlgorithmParametersSpi spi; 11 private Provider provider; 12 private String algorithm; 13 AlgorithmParameters( AlgorithmParametersSpi paramSpi, Provider provider, String algorithm)14 protected AlgorithmParameters( 15 AlgorithmParametersSpi paramSpi, 16 Provider provider, 17 String algorithm) 18 { 19 this.spi = paramSpi; 20 this.provider = provider; 21 this.algorithm = algorithm; 22 } 23 getAlgorithm()24 public final String getAlgorithm() 25 { 26 return algorithm; 27 } 28 getEncoded()29 public final byte[] getEncoded() throws IOException 30 { 31 return spi.engineGetEncoded(); 32 } 33 getEncoded(String format)34 public final byte[] getEncoded(String format) throws IOException 35 { 36 return spi.engineGetEncoded(format); 37 } 38 getInstance(String algorithm)39 public static AlgorithmParameters getInstance(String algorithm) 40 throws NoSuchAlgorithmException 41 { 42 try 43 { 44 SecurityUtil.Implementation imp = SecurityUtil.getImplementation("AlgorithmParameters", algorithm, null); 45 46 if (imp != null) 47 { 48 return new AlgorithmParameters((AlgorithmParametersSpi)imp.getEngine(), imp.getProvider(), algorithm); 49 } 50 51 throw new NoSuchAlgorithmException("can't find algorithm " + algorithm); 52 } 53 catch (NoSuchProviderException e) 54 { 55 throw new NoSuchAlgorithmException(algorithm + " not found"); 56 } 57 } 58 getInstance(String algorithm, String provider)59 public static AlgorithmParameters getInstance(String algorithm, String provider) 60 throws NoSuchAlgorithmException, NoSuchProviderException 61 { 62 SecurityUtil.Implementation imp = SecurityUtil.getImplementation("AlgorithmParameters", algorithm, provider); 63 64 if (imp != null) 65 { 66 return new AlgorithmParameters((AlgorithmParametersSpi)imp.getEngine(), imp.getProvider(), algorithm); 67 } 68 69 throw new NoSuchAlgorithmException("can't find algorithm " + algorithm); 70 } 71 getParameterSpec(Class paramSpec)72 public final AlgorithmParameterSpec getParameterSpec(Class paramSpec) 73 throws InvalidParameterSpecException 74 { 75 return spi.engineGetParameterSpec(paramSpec); 76 } 77 getProvider()78 public final Provider getProvider() 79 { 80 return provider; 81 } 82 init(AlgorithmParameterSpec paramSpec)83 public final void init(AlgorithmParameterSpec paramSpec) 84 throws InvalidParameterSpecException 85 { 86 spi.engineInit(paramSpec); 87 } 88 init(byte[] params)89 public final void init(byte[] params) throws IOException 90 { 91 spi.engineInit(params); 92 } 93 init(byte[] params, String format)94 public final void init(byte[] params, String format) throws IOException 95 { 96 spi.engineInit(params, format); 97 } 98 toString()99 public final String toString() 100 { 101 return spi.engineToString(); 102 } 103 } 104