1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52:
53:
61: public class DSSKeyPairGeneratorSpi
62: extends KeyPairGeneratorAdapter
63: implements DSAKeyPairGenerator
64: {
65: public DSSKeyPairGeneratorSpi()
66: {
67: super(Registry.DSS_KPG);
68: }
69:
70: public void initialize(int keysize, SecureRandom random)
71: {
72: this.initialize(keysize, false, random);
73: }
74:
75: public void initialize(AlgorithmParameterSpec params, SecureRandom random)
76: throws InvalidAlgorithmParameterException
77: {
78: HashMap attributes = new HashMap();
79: if (params != null)
80: {
81: if (! (params instanceof DSAParameterSpec))
82: throw new InvalidAlgorithmParameterException(
83: "Parameters argument is not a non-null instance, or "
84: + "sub-instance, of java.security.spec.DSAParameterSpec");
85: attributes.put(DSSKeyPairGenerator.DSS_PARAMETERS, params);
86: }
87: if (random != null)
88: attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
89:
90: attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
91: Integer.valueOf(Registry.ASN1_ENCODING_ID));
92: try
93: {
94: adaptee.setup(attributes);
95: }
96: catch (IllegalArgumentException x)
97: {
98: throw new InvalidAlgorithmParameterException(x.getMessage(), x);
99: }
100: }
101:
102: public void initialize(DSAParams params, SecureRandom random)
103: throws InvalidParameterException
104: {
105: if (params == null || !(params instanceof DSAParameterSpec))
106: throw new InvalidParameterException(
107: "Parameters argument is either null or is not an instance, or "
108: + "sub-instance, of java.security.spec.DSAParameterSpec");
109: DSAParameterSpec spec = (DSAParameterSpec) params;
110: try
111: {
112: this.initialize((AlgorithmParameterSpec) spec, random);
113: }
114: catch (InvalidAlgorithmParameterException x)
115: {
116: InvalidParameterException y = new InvalidParameterException(x.getMessage());
117: y.initCause(x);
118: throw y;
119: }
120: }
121:
122: public void initialize(int modlen, boolean genParams, SecureRandom random)
123: throws InvalidParameterException
124: {
125: HashMap attributes = new HashMap();
126: attributes.put(DSSKeyPairGenerator.MODULUS_LENGTH, Integer.valueOf(modlen));
127: if (random != null)
128: attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
129:
130: attributes.put(DSSKeyPairGenerator.USE_DEFAULTS,
131: Boolean.valueOf(! genParams));
132: attributes.put(DSSKeyPairGenerator.STRICT_DEFAULTS, Boolean.TRUE);
133: attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
134: Integer.valueOf(Registry.ASN1_ENCODING_ID));
135: try
136: {
137: adaptee.setup(attributes);
138: }
139: catch (IllegalArgumentException x)
140: {
141: InvalidParameterException y = new InvalidParameterException(x.getMessage());
142: y.initCause(x);
143: throw y;
144: }
145: }
146: }