Package org.omegazero.net.util
Class PrivateKeyReader
java.lang.Object
org.omegazero.net.util.PrivateKeyReader
Class for reading a RSA or EC private key from a PEM-formatted string.
It can read PEM files with PKCS#8 or PKCS#1 encodings. It does not support encrypted PEM files.
This implementation is from here (archived page). For more information and a link to the original source code, see the license header of this source file.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic RSAPrivateCrtKeySpec
getRSAKeySpec
(byte[] keyBytes) Convert PKCS#1 encoded private key into RSAPrivateCrtKeySpec.static PrivateKey
Parses the given PEM-formatted string representing a private key.
-
Field Details
-
P1_BEGIN_MARKER
- See Also:
-
P1_END_MARKER
- See Also:
-
P8_BEGIN_MARKER
- See Also:
-
P8_END_MARKER
- See Also:
-
-
Method Details
-
read
Parses the given PEM-formatted string representing a private key.- Returns:
- The
PrivateKey
- Throws:
IOException
- If the given key string is malformedGeneralSecurityException
- If the given key string could not be parsed
-
getRSAKeySpec
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 }
- Parameters:
keyBytes
- PKCS#1 encoded key- Returns:
- KeySpec
- Throws:
IOException
-