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

DSAPublicKeyImpl

public class DSAPublicKeyImpl extends org.apache.harmony.security.PublicKeyImpl implements DSAPublicKey
The class provides DSAPublicKey functionality by extending a class implementing PublicKey and implementing methods defined in both interfaces, DSAKey and DSAPublicKey

Fields Summary
private static final long
serialVersionUID
private BigInteger
y
private DSAParams
params
Constructors Summary
public DSAPublicKeyImpl(DSAPublicKeySpec keySpec)
Creates object from DSAPublicKeySpec.

param
keySpec - a DSAPublicKeySpec object


                   
       

        super("DSA"); //$NON-NLS-1$

        SubjectPublicKeyInfo spki;

        BigInteger p = keySpec.getP();
        BigInteger q = keySpec.getQ();
        BigInteger g = keySpec.getG();

        ThreeIntegerSequence threeInts = new ThreeIntegerSequence(p
                .toByteArray(), q.toByteArray(), g.toByteArray());

        AlgorithmIdentifier ai = new AlgorithmIdentifier(AlgNameMapper
                .map2OID("DSA"), //$NON-NLS-1$
                threeInts.getEncoded());

        y = keySpec.getY();

        spki = new SubjectPublicKeyInfo(ai, ASN1Integer.getInstance().encode(
                y.toByteArray()));
        setEncoding(spki.getEncoded());

        params = (DSAParams) (new DSAParameterSpec(p, q, g));
    
public DSAPublicKeyImpl(X509EncodedKeySpec keySpec)
Creates object from X509EncodedKeySpec.

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


        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$
        }
        params = (DSAParams) (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
DSA key parameters (p, q, g).

        return params;
    
public java.math.BigIntegergetY()

return
a value of a public key (y).

        return y;