1 7 8 package java.security; 9 10 import java.security.spec.AlgorithmParameterSpec ; 11 12 60 61 public class AlgorithmParameterGenerator { 62 63 private Provider provider; 65 66 private AlgorithmParameterGeneratorSpi paramGenSpi; 68 69 private String algorithm; 71 72 79 protected AlgorithmParameterGenerator 80 (AlgorithmParameterGeneratorSpi paramGenSpi, Provider provider, 81 String algorithm) { 82 this.paramGenSpi = paramGenSpi; 83 this.provider = provider; 84 this.algorithm = algorithm; 85 } 86 87 93 public final String getAlgorithm() { 94 return this.algorithm; 95 } 96 97 114 public static AlgorithmParameterGenerator getInstance(String algorithm) 115 throws NoSuchAlgorithmException { 116 try { 117 Object [] objs = Security.getImpl(algorithm, 118 "AlgorithmParameterGenerator", 119 (String )null); 120 return new AlgorithmParameterGenerator 121 ((AlgorithmParameterGeneratorSpi )objs[0], 122 (Provider )objs[1], 123 algorithm); 124 } catch(NoSuchProviderException e) { 125 throw new NoSuchAlgorithmException (algorithm + " not found"); 126 } 127 } 128 129 151 public static AlgorithmParameterGenerator getInstance(String algorithm, 152 String provider) 153 throws NoSuchAlgorithmException , NoSuchProviderException 154 { 155 if (provider == null || provider.length() == 0) 156 throw new IllegalArgumentException ("missing provider"); 157 Object [] objs = Security.getImpl(algorithm, 158 "AlgorithmParameterGenerator", 159 provider); 160 return new AlgorithmParameterGenerator 161 ((AlgorithmParameterGeneratorSpi )objs[0], (Provider )objs[1], 162 algorithm); 163 } 164 165 187 public static AlgorithmParameterGenerator getInstance(String algorithm, 188 Provider provider) 189 throws NoSuchAlgorithmException 190 { 191 if (provider == null) 192 throw new IllegalArgumentException ("missing provider"); 193 Object [] objs = Security.getImpl(algorithm, 194 "AlgorithmParameterGenerator", 195 provider); 196 return new AlgorithmParameterGenerator 197 ((AlgorithmParameterGeneratorSpi )objs[0], (Provider )objs[1], 198 algorithm); 199 } 200 201 206 public final Provider getProvider() { 207 return this.provider; 208 } 209 210 221 public final void init(int size) { 222 paramGenSpi.engineInit(size, new SecureRandom ()); 223 } 224 225 232 public final void init(int size, SecureRandom random) { 233 paramGenSpi.engineInit(size, random); 234 } 235 236 251 public final void init(AlgorithmParameterSpec genParamSpec) 252 throws InvalidAlgorithmParameterException { 253 paramGenSpi.engineInit(genParamSpec, new SecureRandom ()); 254 } 255 256 266 public final void init(AlgorithmParameterSpec genParamSpec, 267 SecureRandom random) 268 throws InvalidAlgorithmParameterException { 269 paramGenSpi.engineInit(genParamSpec, random); 270 } 271 272 277 public final AlgorithmParameters generateParameters() { 278 return paramGenSpi.engineGenerateParameters(); 279 } 280 } 281 | Popular Tags |