Source is from https://web.archive.org/web/20110827064643/http://oauth.googlecode.com:80/svn/code/branches/jmeter/jmeter/src/main/java/org/apache/jmeter/protocol/oauth/sampler/PrivateKeyReader.java which is licensed under the APL (see also https://web.archive.org/web/20120202095848/http://code.google.com:80/p/jmeter-oauth/)
All credits go to the original author Zhihong Zhang (zhihong@gmail)
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | PrivateKeyParser.
An ASN.1 TLV. |
| pack-priv static class | PrivateKeyParser.
A bare-minimum ASN.1 DER decoder, just having enough functions to decode PKCS#1 private keys. |
| Modifier and Type | Field and Description |
|---|---|
| private static final byte[] | OID_EC_PUBLIC_KEY
ASN.1 OID for EC public key. |
| private static final byte[] | OID_RSA_PUBLIC_KEY
ASN.1 OID for RSA public key. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static ECPrivateKeySpec | Returns: The spec that can be used to instantiate the private key.The encoded key. keyBytes)Converts a DER encoded ECPrivateKey into a Java ECPrivateKeySpec. |
| private static ECParameterSpec | |
| public static String | Returns: The algorithm name, either RSA or EC, depending on the algorithm identifier found in the encoded key.The encoded private key. encodedKey)Gets the algorithm used by a PKCS#8 encoded private key. |
| public static RSAPrivateCrtKeySpec | Returns: KeySpecPKCS#1 encoded key keyBytes)Convert PKCS#1 encoded private key into RSAPrivateCrtKeySpec. |
| private static String |
| OID_EC_PUBLIC_KEY | back to summary |
|---|---|
| private static final byte[] OID_EC_PUBLIC_KEY ASN.1 OID for EC public key. | |
| OID_RSA_PUBLIC_KEY | back to summary |
|---|---|
| private static final byte[] OID_RSA_PUBLIC_KEY ASN.1 OID for RSA public key. | |
| PrivateKeyParser | back to summary |
|---|---|
| public PrivateKeyParser() | |
| getECKeySpec | back to summary |
|---|---|
| public static ECPrivateKeySpec getECKeySpec(byte[] keyBytes) throws VertxException Converts a DER encoded ECPrivateKey into a Java ECPrivateKeySpec. RFC 5915 defines the following ASN.1 syntax for an EC private key:
ECPrivateKey ::= SEQUENCE {
version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
privateKey OCTET STRING,
parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
publicKey [1] BIT STRING OPTIONAL
}
A private key encoded like this will most often be found in a PEM file which will contain the Base64 encoded DER-encoding of an ECPrivateKey sandwiched between -----BEGIN EC PRIVATE KEY----- -----END EC PRIVATE KEY-----as described in RFC 5915, Section 4
| |
| getECParameterSpec | back to summary |
|---|---|
| private static ECParameterSpec getECParameterSpec(String curveName) throws VertxException | |
| getPKCS8EncodedKeyAlgorithm | back to summary |
|---|---|
| public static String getPKCS8EncodedKeyAlgorithm(byte[] encodedKey) Gets the algorithm used by a PKCS#8 encoded private key.
| |
| getRSAKeySpec | back to summary |
|---|---|
| public static RSAPrivateCrtKeySpec getRSAKeySpec(byte[] keyBytes) throws VertxException Convert PKCS#1 encoded private key into RSAPrivateCrtKeySpec.
The ASN.1 syntax for the private key with CRT is
--
-- Representation of RSA private key with information for the CRT algorithm.
--
RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}
| |
| oidToString | back to summary |
|---|---|
| private static String oidToString(byte[] oid) | |
| Modifier and Type | Field and Description |
|---|---|
| protected final int | |
| protected final int | |
| protected final int | |
| protected final byte[] |
| Access | Constructor and Description |
|---|---|
| public | Asn1Object(int
Tag or Identifier tag, int Length of the field length, byte[] Encoded octet string for the field. value)Construct a ASN.1 TLV. |
| Modifier and Type | Method and Description |
|---|---|
| public BigInteger | |
| public int | |
| public byte[] | |
| public PrivateKeyParser. | Returns: A parser for the construct.For constructed field, return a parser for its content. |
| public String | |
| public int | |
| public byte[] | |
| public boolean |
| length | back to summary |
|---|---|
| protected final int length | |
| tag | back to summary |
|---|---|
| protected final int tag | |
| type | back to summary |
|---|---|
| protected final int type | |
| value | back to summary |
|---|---|
| protected final byte[] value | |
| Asn1Object | back to summary |
|---|---|
| public Asn1Object(int tag, int length, byte[] value) Construct a ASN.1 TLV. The TLV could be either a constructed or primitive entity.
The first byte in DER encoding is made of following fields, ------------------------------------------------- |Bit 8|Bit 7|Bit 6|Bit 5|Bit 4|Bit 3|Bit 2|Bit 1| ------------------------------------------------- | Class | CF | + Type | -------------------------------------------------
| |
| getInteger | back to summary |
|---|---|
| public BigInteger getInteger() throws VertxException Get the value as integer
| |
| getLength | back to summary |
|---|---|
| public int getLength() | |
| getObjectIdentifier | back to summary |
|---|---|
| public byte[] getObjectIdentifier() throws VertxException | |
| getParser | back to summary |
|---|---|
| public PrivateKeyParser. For constructed field, return a parser for its content.
| |
| getString | back to summary |
|---|---|
| public String getString() throws VertxException Get value as string. Most strings are treated as Latin-1.
| |
| getType | back to summary |
|---|---|
| public int getType() | |
| getValue | back to summary |
|---|---|
| public byte[] getValue() | |
| isConstructed | back to summary |
|---|---|
| public boolean isConstructed() | |
This parser can only handle one layer. To parse nested constructs,
get a new parser for each layer using Asn1Object.getParser().
There are many DER decoders in JRE but using them will tie this program to a specific JCE/JVM.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private Buffer | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private int | |
| public PrivateKeyParser. | |
| private int | |
| private byte[] |
| ANY | back to summary |
|---|---|
| private static final int ANY | |
| APPLICATION | back to summary |
|---|---|
| private static final int APPLICATION | |
| BIT_STRING | back to summary |
|---|---|
| private static final int BIT_STRING | |
| BMP_STRING | back to summary |
|---|---|
| private static final int BMP_STRING | |
| BOOLEAN | back to summary |
|---|---|
| private static final int BOOLEAN | |
| CONSTRUCTED | back to summary |
|---|---|
| private static final int CONSTRUCTED | |
| CONTEXT | back to summary |
|---|---|
| private static final int CONTEXT | |
| ENUMERATED | back to summary |
|---|---|
| private static final int ENUMERATED | |
| GENERAL_STRING | back to summary |
|---|---|
| private static final int GENERAL_STRING | |
| GRAPHIC_STRING | back to summary |
|---|---|
| private static final int GRAPHIC_STRING | |
| IA5_STRING | back to summary |
|---|---|
| private static final int IA5_STRING | |
| in | back to summary |
|---|---|
| private Buffer in
References Deprecated
See corresponding docs for further information. | |
| INTEGER | back to summary |
|---|---|
| private static final int INTEGER | |
| ISO646_STRING | back to summary |
|---|---|
| private static final int ISO646_STRING | |
| NULL | back to summary |
|---|---|
| private static final int NULL | |
| NUMERIC_STRING | back to summary |
|---|---|
| private static final int NUMERIC_STRING | |
| OBJECT_IDENTIFIER | back to summary |
|---|---|
| private static final int OBJECT_IDENTIFIER | |
| OCTET_STRING | back to summary |
|---|---|
| private static final int OCTET_STRING | |
| pos | back to summary |
|---|---|
| private int pos | |
| PRINTABLE_STRING | back to summary |
|---|---|
| private static final int PRINTABLE_STRING | |
| PRIVATE | back to summary |
|---|---|
| private static final int PRIVATE | |
| REAL | back to summary |
|---|---|
| private static final int REAL | |
| SEQUENCE | back to summary |
|---|---|
| private static final int SEQUENCE | |
| SET | back to summary |
|---|---|
| private static final int SET | |
| UNIVERSAL | back to summary |
|---|---|
| private static final int UNIVERSAL | |
| UNIVERSAL_STRING | back to summary |
|---|---|
| private static final int UNIVERSAL_STRING | |
| UTC_TIME | back to summary |
|---|---|
| private static final int UTC_TIME | |
| UTF8_STRING | back to summary |
|---|---|
| private static final int UTF8_STRING | |
| VIDEOTEX_STRING | back to summary |
|---|---|
| private static final int VIDEOTEX_STRING | |
| DerParser | back to summary |
|---|---|
| pack-priv DerParser(Buffer in) throws VertxException
References Deprecated
See corresponding docs for further information. Create a new DER decoder from an input stream.
| |
| DerParser | back to summary |
|---|---|
| pack-priv DerParser(byte[] bytes) throws VertxException Create a new DER decoder from a byte array.
| |
| getLength | back to summary |
|---|---|
| private int getLength() throws VertxException Decode the length of the field. Can only support length encoding up to 4 octets.
In BER/DER encoding, length can be encoded in 2 forms,
| |
| read | back to summary |
|---|---|
| public PrivateKeyParser. Read next object. If it's constructed, the value holds
encoded content and it should be parsed by a new
parser from
| |
| readByte | back to summary |
|---|---|
| private int readByte() throws VertxException | |
| readBytes | back to summary |
|---|---|
| private byte[] readBytes(int len) throws VertxException | |