Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
gnu.javax.crypto.key.dh.DHKeyPairX509Codec
Fields inherited from interface gnu.java.security.key.IKeyPairCodec | |
ASN1_FORMAT , PKCS8_FORMAT , RAW_FORMAT , X509_FORMAT |
Method Summary | |
PrivateKey |
|
PublicKey |
|
byte[] | |
byte[] |
|
int |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public PrivateKey decodePrivateKey(byte[] input)
- Specified by:
- decodePrivateKey in interface IKeyPairCodec
- Throws:
InvalidParameterException
- ALWAYS.
public PublicKey decodePublicKey(byte[] input)
- Specified by:
- decodePublicKey in interface IKeyPairCodec
- Parameters:
input
- the byte array to unmarshall into a valid DHPublicKey
instance. MUST NOT be null.
- Returns:
- a new instance of a
GnuDHPublicKey
decoded from the SubjectPublicKeyInfo material in an X.509 certificate.
public byte[] encodePrivateKey(PrivateKey key)
- Specified by:
- encodePrivateKey in interface IKeyPairCodec
- Throws:
InvalidParameterException
- ALWAYS.
public byte[] encodePublicKey(PublicKey key)
Returns the DER-encoded form of the X.509 ASN.1 SubjectPublicKeyInfo representation of a DH public key. The ASN.1 specification, as defined in RFC-3280, and RFC-2459, is as follows:SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, subjectPublicKey BIT STRING } AlgorithmIdentifier ::= SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY DEFINED BY algorithm OPTIONAL } DhParams ::= SEQUENCE { p INTEGER, -- odd prime, p=jq +1 g INTEGER, -- generator, g q INTEGER -- factor of p-1 }The subjectPublicKey field, which is a BIT STRING, contains the DER-encoded form of the DH public key as an INTEGER.DHPublicKey ::= INTEGER -- public key, y = g^x mod pIMPORTANT: with RI'sDHGenParameterSpec
andDHParameterSpec
classes, we may end up with Diffie-Hellman keys that have anull
for theq
parameter. RFC-2631 DOES NOT allow for an optional value for that parameter, hence we replace such null values with0
, and do the reverse in the corresponding decode method.
- Specified by:
- encodePublicKey in interface IKeyPairCodec
- Parameters:
key
- thePublicKey
instance to encode. MUST be an instance ofGnuDHPublicKey
.
- Returns:
- the DER-encoded form of the ASN.1 representation of the SubjectPublicKeyInfo in an X.509 certificate.