public DSAPrivateKeyImpl(PKCS8EncodedKeySpec keySpec)
throws InvalidKeySpecException {
super("DSA"); //$NON-NLS-1$
AlgorithmIdentifier ai;
ThreeIntegerSequence threeInts = null;
String alg, algName;
byte encoding[] = keySpec.getEncoded();
PrivateKeyInfo privateKeyInfo = null;
try {
privateKeyInfo = (PrivateKeyInfo) PrivateKeyInfo.ASN1
.decode(encoding);
} catch (IOException e) {
throw new InvalidKeySpecException(Messages.getString(
"security.19A", e)); //$NON-NLS-1$
}
try {
x = new BigInteger((byte[]) ASN1Integer.getInstance().decode(
privateKeyInfo.getPrivateKey()));
} catch (IOException e) {
throw new InvalidKeySpecException(Messages.getString(
"security.19B", e)); //$NON-NLS-1$
}
ai = privateKeyInfo.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 = 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);
}