sun.security.x509
Class AlgIdDSA

java.lang.Object
  extended by sun.security.x509.AlgorithmId
      extended by sun.security.x509.AlgIdDSA
All Implemented Interfaces:
Serializable, DSAParams, DerEncoder

public final class AlgIdDSA
extends AlgorithmId
implements DSAParams

This class identifies DSS/DSA Algorithm variants, which are distinguished by using different algorithm parameters P, Q, G. It uses the NIST/IETF standard DER encoding. These are used to implement the Digital Signature Standard (DSS), FIPS 186.

NOTE: DSS/DSA Algorithm IDs may be created without these parameters. Use of DSS/DSA in modes where parameters are either implicit (e.g. a default applicable to a site or a larger scope), or are derived from some Certificate Authority's DSS certificate, is not supported directly. The application is responsible for creating a key containing the required parameters prior to using the key in cryptographic operations. The follwoing is an example of how this may be done assuming that we have a certificate called currentCert which doesn't contain DSS/DSA parameters and we need to derive DSS/DSA parameters from a CA's certificate called caCert.

 // key containing parameters to use
 DSAPublicKey cAKey = (DSAPublicKey)(caCert.getPublicKey());
 // key without parameters
 DSAPublicKey nullParamsKey = (DSAPublicKey)(currentCert.getPublicKey()); 

 DSAParams cAKeyParams = cAKey.getParams();
 KeyFactory kf = KeyFactory.getInstance("DSA");
 DSAPublicKeySpec ks = new DSAPublicKeySpec(nullParamsKey.getY(),
                                            cAKeyParams.getP(),
                                            cAKeyParams.getQ(),
                                            cAKeyParams.getG());
 DSAPublicKey usableKey = kf.generatePublic(ks);
 

See Also:
DSAParams, DSAPublicKey, KeyFactory, DSAPublicKeySpec, Serialized Form

Field Summary
 
Fields inherited from class sun.security.x509.AlgorithmId
DH_oid, DH_PKIX_oid, DSA_oid, DSA_OIW_oid, MD2_oid, md2WithRSAEncryption_oid, MD5_oid, md5WithRSAEncryption_oid, params, RSA_oid, RSAEncryption_oid, SHA_oid, SHA1_OIW_oid, sha1WithDSA_oid, sha1WithDSA_OIW_oid, sha1WithRSAEncryption_oid, sha1WithRSAEncryption_OIW_oid, SHA5_oid, shaWithDSA_OIW_oid
 
Constructor Summary
AlgIdDSA()
          Default constructor.
AlgIdDSA(BigInteger p, BigInteger q, BigInteger g)
          Constructs a DSS/DSA Algorithm ID from numeric parameters.
AlgIdDSA(byte[] encodedAlg)
          Construct an AlgIdDSA from an X.509 encoded byte array.
AlgIdDSA(byte[] p, byte[] q, byte[] g)
          Constructs a DSS/DSA Algorithm ID from unsigned integers that define the algorithm parameters.
 
Method Summary
protected  void decodeParams()
          Parses algorithm parameters P, Q, and G.
 BigInteger getG()
          Returns the DSS/DSA parameter "G"
 String getName()
          Returns "DSA", indicating the Digital Signature Algorithm (DSA) as defined by the Digital Signature Standard (DSS), FIPS 186.
 BigInteger getP()
          Returns the DSS/DSA parameter "P"
 BigInteger getQ()
          Returns the DSS/DSA parameter "Q"
protected  String paramsToString()
          Provides a human-readable description of the algorithm parameters.
 String toString()
          Returns a string describing the algorithm and its parameters.
 
Methods inherited from class sun.security.x509.AlgorithmId
derEncode, encode, encode, equals, equals, equals, get, get, getAlgorithmId, getEncodedParams, getOID, getParameters, hashCode, parse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AlgIdDSA

public AlgIdDSA()
Default constructor. The OID and parameters must be deserialized before this algorithm ID is used.


AlgIdDSA

public AlgIdDSA(byte[] encodedAlg)
         throws IOException
Construct an AlgIdDSA from an X.509 encoded byte array.

Throws:
IOException

AlgIdDSA

public AlgIdDSA(byte[] p,
                byte[] q,
                byte[] g)
         throws IOException
Constructs a DSS/DSA Algorithm ID from unsigned integers that define the algorithm parameters. Those integers are encoded as big-endian byte arrays.

Parameters:
p - the DSS/DSA paramter "P"
q - the DSS/DSA paramter "Q"
g - the DSS/DSA paramter "G"
Throws:
IOException

AlgIdDSA

public AlgIdDSA(BigInteger p,
                BigInteger q,
                BigInteger g)
Constructs a DSS/DSA Algorithm ID from numeric parameters. If all three are null, then the parameters portion of the algorithm id is set to null. See note in header regarding use.

Parameters:
p - the DSS/DSA paramter "P"
q - the DSS/DSA paramter "Q"
g - the DSS/DSA paramter "G"
Method Detail

getP

public BigInteger getP()
Returns the DSS/DSA parameter "P"

Specified by:
getP in interface DSAParams
Returns:
the prime, p.

getQ

public BigInteger getQ()
Returns the DSS/DSA parameter "Q"

Specified by:
getQ in interface DSAParams
Returns:
the subprime, q.

getG

public BigInteger getG()
Returns the DSS/DSA parameter "G"

Specified by:
getG in interface DSAParams
Returns:
the base, g.

getName

public String getName()
Returns "DSA", indicating the Digital Signature Algorithm (DSA) as defined by the Digital Signature Standard (DSS), FIPS 186.

Overrides:
getName in class AlgorithmId

decodeParams

protected void decodeParams()
                     throws IOException
Parses algorithm parameters P, Q, and G. They're found in the "params" member, which never needs to be changed.

Overrides:
decodeParams in class AlgorithmId
Throws:
IOException

toString

public String toString()
Description copied from class: AlgorithmId
Returns a string describing the algorithm and its parameters.

Overrides:
toString in class AlgorithmId
Returns:
a string representation of the object.

paramsToString

protected String paramsToString()
Description copied from class: AlgorithmId
Provides a human-readable description of the algorithm parameters. This may be redefined by subclasses which parse those parameters.

Overrides:
paramsToString in class AlgorithmId