FileDocCategorySizeDatePackage
DSAPrivateKeyImpl.javaAPI DocAndroid 1.5 API5145Wed May 06 22:41:06 BST 2009org.apache.harmony.security.provider.crypto

DSAPrivateKeyImpl

public class DSAPrivateKeyImpl extends org.apache.harmony.security.PrivateKeyImpl implements DSAPrivateKey
The 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.

param
keySpec - a DSAPrivateKeySpec object


                   
       

        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.

param
keySpec - a XPKCS8EncodedKeySpec object
throws
InvalidKeySpecException - if key data cannot be obtain from encoded format


        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);
    
Methods Summary
public java.security.interfaces.DSAParamsgetParams()

        return params;
    
public java.math.BigIntegergetX()

        return x;