Class AlgorithmId
- java.lang.Object
-
- org.mozilla.jss.netscape.security.x509.AlgorithmId
-
- All Implemented Interfaces:
java.io.Serializable,DerEncoder
- Direct Known Subclasses:
AlgIdDSA
public class AlgorithmId extends java.lang.Object implements java.io.Serializable, DerEncoder
This class identifies algorithms, such as cryptographic transforms, each of which may be associated with parameters. Instances of this base class are used when this runtime environment has no special knowledge of the algorithm type, and may also be used in other cases. Equivalence is defined according to OID and (where relevant) parameters.Subclasses may be used, for example when when the algorithm ID has associated parameters which some code (e.g. code using public keys) needs to have parsed. Two examples of such algorithms are Diffie-Hellman key exchange, and the Digital Signature Standard Algorithm (DSS/DSA).
The OID constants defined in this class correspond to some widely used algorithms, for which conventional string names have been defined. This class is not a general repository for OIDs, or for such string names. Note that the mappings between algorithm IDs and algorithm names is not one-to-one.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String[]ALL_SIGNING_ALGORITHMSAll supported signing algorithms.static ObjectIdentifierANSIX962_EC_Public_Key_oidstatic ObjectIdentifierANSIX962_SHA1_With_EC_oidstatic ObjectIdentifierDH_oidAlgorithm ID for Diffie Hellman Key agreement, from PKCS #3.static ObjectIdentifierDH_PKIX_oidAlgorithm ID for the Diffie Hellman Key Agreement (DH), from the IETF PKIX IPKI Part I.static ObjectIdentifierDSA_oidAlgorithm ID for the Digital Signing Algorithm (DSA), from the IETF PKIX IPKI Part I.static ObjectIdentifierDSA_OIW_oidAlgorithm ID for the Digital Signing Algorithm (DSA), from the NIST OIW Stable Agreements part 12.static java.lang.String[]DSA_SIGNING_ALGORITHMSSupported signing algorithms for a DSA key.static java.lang.String[]EC_SIGNING_ALGORITHMSstatic ObjectIdentifierMD2_oidAlgorithm ID for the MD2 Message Digest Algorthm, from RFC 1319.static ObjectIdentifiermd2WithRSAEncryption_oidIdentifies a signing algorithm where an MD2 digest is encrypted using an RSA private key; defined in PKCS #1.static ObjectIdentifierMD5_oidAlgorithm ID for the MD5 Message Digest Algorthm, from RFC 1321.static ObjectIdentifiermd5WithRSAEncryption_oidIdentifies a signing algorithm where an MD5 digest is encrypted using an RSA private key; defined in PKCS #1.protected DerValueparamsParameters for this algorithm.protected java.lang.StringparamsStringstatic ObjectIdentifierRSA_oidAlgorithm ID for RSA keys used for any purpose, as defined in X.509.static java.lang.String[]RSA_SIGNING_ALGORITHMSSupported signing algorithms for a RSA key.static ObjectIdentifierRSAEncryption_oidAlgorithm ID for RSA keys used with RSA encryption, as defined in PKCS #1.static ObjectIdentifierSHA_oidAlgorithm ID for the SHA1 Message Digest Algorithm, from FIPS 180-1.static ObjectIdentifiersha1WithDSA_oidIdentifies the FIPS 186 "Digital Signature Standard" (DSS), where a SHA1 digest is signed using the Digital Signing Algorithm (DSA).static ObjectIdentifiersha1WithDSA_OIW_oidIdentifies the FIPS 186 "Digital Signature Standard" (DSS), where a SHA1 digest is signed using the Digital Signing Algorithm (DSA).static ObjectIdentifiersha1WithEC_oidstatic ObjectIdentifiersha1WithRSAEncryption_oidThe proper one for sha1/rsastatic ObjectIdentifiersha1WithRSAEncryption_OIW_oidIdentifies a signing algorithm where an SHA1 digest is encrypted using an RSA private key; defined in NIST OIW.static ObjectIdentifiersha224WithEC_oidstatic ObjectIdentifierSHA256_oidstatic ObjectIdentifiersha256WithEC_oidstatic ObjectIdentifiersha256WithRSAEncryption_oidThe proper one for sha256/rsastatic ObjectIdentifierSHA384_oidstatic ObjectIdentifiersha384WithEC_oidstatic ObjectIdentifiersha384WithRSAEncryption_oidThe proper one for sha384/rsastatic ObjectIdentifierSHA512_oidstatic ObjectIdentifiersha512WithEC_oidstatic ObjectIdentifiersha512WithRSAEncryption_oidThe proper one for sha512/rsastatic ObjectIdentifiershaWithDSA_OIW_oidIdentifies the FIPS 186 "Digital Signature Standard" (DSS), where a SHA digest is signed using the Digital Signing Algorithm (DSA).
-
Constructor Summary
Constructors Constructor Description AlgorithmId()Deprecated.use one of the other constructors.AlgorithmId(ObjectIdentifier oid)Constructs a parameterless algorithm ID.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecodeParams()voidderEncode(java.io.OutputStream out)DER encode this object onto an output stream.byte[]encode()Returns the DER-encoded X.509 AlgorithmId as a byte array.voidencode(DerOutputStream out)Marshal a DER-encoded "AlgorithmID" sequence on the DER stream.booleanequals(java.lang.Object other)Compares this AlgorithmID to another.booleanequals(ObjectIdentifier id)Compares two algorithm IDs for equality.booleanequals(AlgorithmId other)Returns true iff the argument indicates the same algorithm with the same parameters.static AlgorithmIdget(java.lang.String algname)Returns one of the algorithm IDs most commonly associated with this algorithm name.byte[]getEncodedParams()Returns the DER encoded parameter, which can then be used to initialize java.security.AlgorithmParamters.java.lang.StringgetName()Returns a name for the algorithm which may be more intelligible to humans than the algorithm's OID, but which won't necessarily be comprehensible on other systems.ObjectIdentifiergetOID()Returns the ISO OID for this algorithm.java.security.AlgorithmParametersgetParameters()java.lang.StringgetParametersString()static java.lang.String[]getSigningAlgorithms(AlgorithmId alg)Returns list of signing algorithms for a key algorithm such as RSA or DSA.inthashCode()protected java.lang.StringparamsToString()Provides a human-readable description of the algorithm parameters.static AlgorithmIdparse(byte[] val)static AlgorithmIdparse(DerValue val)Parse (unmarshal) an ID from a DER sequence input value.voidsetParametersString(java.lang.String paramStr)java.lang.StringtoString()Returns a string describing the algorithm and its parameters.
-
-
-
Field Detail
-
params
protected DerValue params
Parameters for this algorithm. These are stored in unparsed DER-encoded form; subclasses can be made to automaticaly parse them so there is fast access to these parameters.
-
paramsString
protected java.lang.String paramsString
-
MD2_oid
public static final ObjectIdentifier MD2_oid
Algorithm ID for the MD2 Message Digest Algorthm, from RFC 1319. OID = 1.2.840.113549.2.2
-
MD5_oid
public static final ObjectIdentifier MD5_oid
Algorithm ID for the MD5 Message Digest Algorthm, from RFC 1321. OID = 1.2.840.113549.2.5
-
SHA_oid
public static final ObjectIdentifier SHA_oid
Algorithm ID for the SHA1 Message Digest Algorithm, from FIPS 180-1. This is sometimes called "SHA", though that is often confusing since many people refer to FIPS 180 (which has an error) as defining SHA. OID = 1.3.14.3.2.26
-
SHA256_oid
public static final ObjectIdentifier SHA256_oid
-
SHA384_oid
public static final ObjectIdentifier SHA384_oid
-
SHA512_oid
public static final ObjectIdentifier SHA512_oid
-
ANSIX962_EC_Public_Key_oid
public static final ObjectIdentifier ANSIX962_EC_Public_Key_oid
-
ANSIX962_SHA1_With_EC_oid
public static final ObjectIdentifier ANSIX962_SHA1_With_EC_oid
-
DH_oid
public static final ObjectIdentifier DH_oid
Algorithm ID for Diffie Hellman Key agreement, from PKCS #3. Parameters include public values P and G, and may optionally specify the length of the private key X. Alternatively, algorithm parameters may be derived from another source such as a Certificate Authority's certificate. OID = 1.2.840.113549.1.3.1
-
DH_PKIX_oid
public static final ObjectIdentifier DH_PKIX_oid
Algorithm ID for the Diffie Hellman Key Agreement (DH), from the IETF PKIX IPKI Part I. Parameters may include public values P and G. OID = 1.2.840.10046.2.1
-
DSA_OIW_oid
public static final ObjectIdentifier DSA_OIW_oid
Algorithm ID for the Digital Signing Algorithm (DSA), from the NIST OIW Stable Agreements part 12. Parameters may include public values P, Q, and G; or these may be derived from another source such as a Certificate Authority's certificate. OID = 1.3.14.3.2.12
-
DSA_oid
public static final ObjectIdentifier DSA_oid
Algorithm ID for the Digital Signing Algorithm (DSA), from the IETF PKIX IPKI Part I. Parameters may include public values P, Q, and G; or these may be derived from another source such as a Certificate Authority's certificate. OID = 1.2.840.10040.4.1
-
RSA_oid
public static final ObjectIdentifier RSA_oid
Algorithm ID for RSA keys used for any purpose, as defined in X.509. The algorithm parameter is a single value, the number of bits in the public modulus. OID = 1.2.5.8.1.1
-
RSAEncryption_oid
public static final ObjectIdentifier RSAEncryption_oid
Algorithm ID for RSA keys used with RSA encryption, as defined in PKCS #1. There are no parameters associated with this algorithm. OID = 1.2.840.113549.1.1.1
-
sha1WithEC_oid
public static final ObjectIdentifier sha1WithEC_oid
-
sha224WithEC_oid
public static final ObjectIdentifier sha224WithEC_oid
-
sha256WithEC_oid
public static final ObjectIdentifier sha256WithEC_oid
-
sha384WithEC_oid
public static final ObjectIdentifier sha384WithEC_oid
-
sha512WithEC_oid
public static final ObjectIdentifier sha512WithEC_oid
-
md2WithRSAEncryption_oid
public static final ObjectIdentifier md2WithRSAEncryption_oid
Identifies a signing algorithm where an MD2 digest is encrypted using an RSA private key; defined in PKCS #1. Use of this signing algorithm is discouraged due to MD2 vulnerabilities. OID = 1.2.840.113549.1.1.2
-
md5WithRSAEncryption_oid
public static final ObjectIdentifier md5WithRSAEncryption_oid
Identifies a signing algorithm where an MD5 digest is encrypted using an RSA private key; defined in PKCS #1. OID = 1.2.840.113549.1.1.4
-
sha1WithRSAEncryption_oid
public static final ObjectIdentifier sha1WithRSAEncryption_oid
The proper one for sha1/rsa
-
sha256WithRSAEncryption_oid
public static final ObjectIdentifier sha256WithRSAEncryption_oid
The proper one for sha256/rsa
-
sha384WithRSAEncryption_oid
public static final ObjectIdentifier sha384WithRSAEncryption_oid
The proper one for sha384/rsa
-
sha512WithRSAEncryption_oid
public static final ObjectIdentifier sha512WithRSAEncryption_oid
The proper one for sha512/rsa
-
sha1WithRSAEncryption_OIW_oid
public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid
Identifies a signing algorithm where an SHA1 digest is encrypted using an RSA private key; defined in NIST OIW. OID = 1.3.14.3.2.29
-
shaWithDSA_OIW_oid
public static final ObjectIdentifier shaWithDSA_OIW_oid
Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a SHA digest is signed using the Digital Signing Algorithm (DSA). This should not be used. OID = 1.3.14.3.2.13
-
sha1WithDSA_OIW_oid
public static final ObjectIdentifier sha1WithDSA_OIW_oid
Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a SHA1 digest is signed using the Digital Signing Algorithm (DSA). OID = 1.3.14.3.2.27
-
sha1WithDSA_oid
public static final ObjectIdentifier sha1WithDSA_oid
Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a SHA1 digest is signed using the Digital Signing Algorithm (DSA). OID = 1.2.840.10040.4.3
-
DSA_SIGNING_ALGORITHMS
public static final java.lang.String[] DSA_SIGNING_ALGORITHMS
Supported signing algorithms for a DSA key.
-
RSA_SIGNING_ALGORITHMS
public static final java.lang.String[] RSA_SIGNING_ALGORITHMS
Supported signing algorithms for a RSA key.
-
EC_SIGNING_ALGORITHMS
public static final java.lang.String[] EC_SIGNING_ALGORITHMS
-
ALL_SIGNING_ALGORITHMS
public static final java.lang.String[] ALL_SIGNING_ALGORITHMS
All supported signing algorithms.
-
-
Constructor Detail
-
AlgorithmId
public AlgorithmId(ObjectIdentifier oid)
Constructs a parameterless algorithm ID.- Parameters:
oid- the identifier for the algorithm
-
AlgorithmId
@Deprecated public AlgorithmId()
Deprecated.use one of the other constructors.Constructs an algorithm ID which will be initialized separately, for example by deserialization.
-
-
Method Detail
-
getParameters
public java.security.AlgorithmParameters getParameters()
-
getParametersString
public java.lang.String getParametersString()
-
setParametersString
public void setParametersString(java.lang.String paramStr)
-
get
public static AlgorithmId get(java.lang.String algname) throws java.security.NoSuchAlgorithmException
Returns one of the algorithm IDs most commonly associated with this algorithm name.- Parameters:
algname- the name being used- Throws:
java.security.NoSuchAlgorithmException- on error.
-
parse
public static AlgorithmId parse(DerValue val) throws java.io.IOException
Parse (unmarshal) an ID from a DER sequence input value. This form parsing might be used when expanding a value which has already been partially unmarshaled as a set or sequence member.- Parameters:
val- the input value, which contains the algid and, if there are any parameters, those parameters.- Returns:
- an ID for the algorithm. If the system is configured appropriately, this may be an instance of a class with some kind of special support for this algorithm. In that case, you may "narrow" the type of the ID.
- Throws:
java.io.IOException- on error.
-
parse
public static AlgorithmId parse(byte[] val) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeParams
protected void decodeParams() throws java.io.IOException- Throws:
java.io.IOException
-
encode
public final void encode(DerOutputStream out) throws java.io.IOException
Marshal a DER-encoded "AlgorithmID" sequence on the DER stream.- Throws:
java.io.IOException
-
derEncode
public void derEncode(java.io.OutputStream out) throws java.io.IOExceptionDER encode this object onto an output stream. Implements theDerEncoderinterface.- Specified by:
derEncodein interfaceDerEncoder- Parameters:
out- the output stream on which to write the DER encoding.- Throws:
java.io.IOException- on encoding error.
-
encode
public final byte[] encode() throws java.io.IOExceptionReturns the DER-encoded X.509 AlgorithmId as a byte array.- Throws:
java.io.IOException
-
getSigningAlgorithms
public static java.lang.String[] getSigningAlgorithms(AlgorithmId alg)
Returns list of signing algorithms for a key algorithm such as RSA or DSA.
-
getOID
public final ObjectIdentifier getOID()
Returns the ISO OID for this algorithm. This is usually converted to a string and used as part of an algorithm name, for example "OID.1.3.14.3.2.13" style notation. Use thegetNamecall when you do not need to ensure cross-system portability of algorithm names, or need a user friendly name.
-
getName
public java.lang.String getName()
Returns a name for the algorithm which may be more intelligible to humans than the algorithm's OID, but which won't necessarily be comprehensible on other systems. For example, this might return a name such as "MD5withRSA" for a signature algorithm on some systems. It also returns names like "OID.1.2.3.4", when no particular name for the algorithm is known.
-
toString
public java.lang.String toString()
Returns a string describing the algorithm and its parameters.- Overrides:
toStringin classjava.lang.Object
-
getEncodedParams
public byte[] getEncodedParams() throws java.io.IOExceptionReturns the DER encoded parameter, which can then be used to initialize java.security.AlgorithmParamters.- Returns:
- DER encoded parameters, or null not present.
- Throws:
java.io.IOException
-
paramsToString
protected java.lang.String paramsToString()
Provides a human-readable description of the algorithm parameters. This may be redefined by subclasses which parse those parameters.
-
equals
public boolean equals(AlgorithmId other)
Returns true iff the argument indicates the same algorithm with the same parameters.
-
equals
public boolean equals(java.lang.Object other)
Compares this AlgorithmID to another. If algorithm parameters are available, they are compared. Otherwise, just the object IDs for the algorithm are compared.- Overrides:
equalsin classjava.lang.Object- Parameters:
other- preferably an AlgorithmId, else an ObjectIdentifier
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(ObjectIdentifier id)
Compares two algorithm IDs for equality. Returns true iff they are the same algorithm, ignoring algorithm parameters.
-
-