DSAPrivateKeyImplpublic class DSAPrivateKeyImpl extends org.apache.harmony.security.PrivateKeyImpl implements DSAPrivateKeyThe class provides DSAPrivateKey functionality by extending a class implementing PrivateKey
and implementing methods defined in both interfaces, DSAKey and DSAPrivateKey |
Fields Summary |
---|
private static final long | serialVersionUID | private BigInteger | x | private DSAParams | params |
Constructors Summary |
---|
public DSAPrivateKeyImpl(DSAPrivateKeySpec keySpec)Creates object from DSAPrivateKeySpec.
super("DSA"); //$NON-NLS-1$
PrivateKeyInfo pki;
BigInteger g = keySpec.getG();
BigInteger p = keySpec.getP();
BigInteger q = keySpec.getQ();
ThreeIntegerSequence threeInts = new ThreeIntegerSequence(p
.toByteArray(), q.toByteArray(), g.toByteArray());
AlgorithmIdentifier ai = new AlgorithmIdentifier(AlgNameMapper
.map2OID("DSA"), //$NON-NLS-1$
threeInts.getEncoded());
x = keySpec.getX();
pki = new PrivateKeyInfo(0, ai, ASN1Integer.getInstance().encode(
x.toByteArray()), null);
setEncoding(pki.getEncoded());
params = new DSAParameterSpec(p, q, g);
| public DSAPrivateKeyImpl(PKCS8EncodedKeySpec keySpec)Creates object from PKCS8EncodedKeySpec.
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$
}
params = new DSAParameterSpec(new BigInteger(threeInts.p),
new BigInteger(threeInts.q), new BigInteger(threeInts.g));
setEncoding(encoding);
/*
* the following code implements RI behavior
*/
alg = ai.getAlgorithm();
algName = AlgNameMapper.map2AlgName(alg);
setAlgorithm(algName == null ? alg : algName);
|
|