public DSAPublicKeyImpl(X509EncodedKeySpec keySpec)
throws InvalidKeySpecException {
super("DSA"); //$NON-NLS-1$
AlgorithmIdentifier ai;
ThreeIntegerSequence threeInts = null;
SubjectPublicKeyInfo subjectPublicKeyInfo = null;
byte encoding[] = keySpec.getEncoded();
String alg, algName;
try {
subjectPublicKeyInfo = (SubjectPublicKeyInfo) SubjectPublicKeyInfo.ASN1
.decode(encoding);
} catch (IOException e) {
throw new InvalidKeySpecException(Messages.getString(
"security.19A", e)); //$NON-NLS-1$
}
try {
y = new BigInteger((byte[]) ASN1Integer.getInstance().decode(
subjectPublicKeyInfo.getSubjectPublicKey()));
} catch (IOException e) {
throw new InvalidKeySpecException(Messages.getString(
"security.19B", e)); //$NON-NLS-1$
}
ai = subjectPublicKeyInfo.getAlgorithmIdentifier();
try {
threeInts = (ThreeIntegerSequence) ThreeIntegerSequence.ASN1
.decode(ai.getParameters());
} catch (IOException e) {
throw new InvalidKeySpecException(Messages.getString(
"security.19B", e)); //$NON-NLS-1$
}
p = new BigInteger(threeInts.p);
q = new BigInteger(threeInts.q);
g = new BigInteger(threeInts.g);
params = (DSAParams) (new DSAParameterSpec(p, q, g));
setEncoding(encoding);
/*
* the following code implements RI behavior
*/
alg = ai.getAlgorithm();
algName = AlgNameMapper.map2AlgName(alg);
setAlgorithm(algName == null ? alg : algName);
}