PublicKey readPublicKey(Path path) {
try (ReadableByteChannel pem = Files.newByteChannel(path)) {
return Pem.decoder()
.decodePublicKey(pem);
}
}
PrivateKey readPrivateKey(Path path) {
try (ReadableByteChannel pem = Files.newByteChannel(path)) {
return Pem.decoder()
.decodePrivateKey(pem);
}
}
PrivateKey readPrivateKey(Path path, char[] passphrase) {
try (ReadableByteChannel pem = Files.newByteChannel(path)) {
return Pem.decoder()
.with(passphrase)
.decodePrivateKey(pem);
}
}
void writePublicKey(Path path,final PublicKey publicKey) {
try (WritableByteChannel pem = Files.newByteChannel(path)) {
return Pem.encoder()
.write(pem,publicKey);
}
}
void writePrivateKey(Path path,final PrivateKey privateKey) {
try (WritableByteChannel pem = Files.newByteChannel(path)) {
return Pem.encoder()
.write(pem,privateKey);
}
}
void writePkcs1PrivateKey(Path path,final PrivateKey privateKey, char[] passphrase) {
try (WritableByteChannel pem = Files.newByteChannel(path)) {
return Pem.encoder()
.with(Pem.Format.LEGACY)
.with(passphrase)
.write(pem,privateKey);
}
}
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static class | Pem.
Decodes PEM encoded text streams into the desired format |
| public static class | Pem.
Encode certificates, public keys and private keys into PEM encoded format |
| public static class | Pem.
Configures how private keys are encrypted |
| public static enum | Pem.
Denotes the specific syntax used for encoding public and private keys (Does not affect the encoding of certificates) |
| private static class | |
| public static interface | Pem.
Holds a passphrase using a try-with-resources model to assure the passphrase plain-text is erased once it has been used |
| pack-priv static enum | Pem.
Denotes the type of content encoded in the PEM message |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final Pem. | |
| private static final Pem. | |
| private static final String | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static byte[] | Returns: PKCS8 encoded bytesPKCS1 encoded bytes pkcs1)Converts PKCS1 to PKCS8 by adding an ASN.1 header to identify the algorithm used to encode the payload (PKCS1 supports RSA only, PKCS8 supports different algorithms). |
| private static byte[] | Returns: X509 Public KeyInfo der encoded bytesPKCS1 encoded bytes pkcs1)Converts PKCS1 to X509 Public KeyInfo by adding an ASN.1 header to identify the algorithm used to encode the payload (PKCS1 supports RSA only, X509 supports different algorithms). |
| private static byte[] | Returns: PKCS1 encoded representation of the keyencoded bytes pkcs8)All Java private keys are PKCS8 encoded. |
| private static byte[] | Returns: PKCS1 encoded representation of the keyX509 encoded public key bytes x509)All Java public keys are X509 encoded. |
| private static byte[] | cryptPkcs1(int mode, byte[] content, Pkcs1EncryptedPrivateKeyInfo encryptedPrivateKeyInfo, Pem.
|
| private static Pem. | |
| public static Pem. | Returns: Decoder instanceReturn a decoder for certificates, public keys and unencrypted private keys. |
| public static Pem. | Returns: Encoder instanceReturn an encoder that does not encrypt private keys and formats private keys in PKCS8, and public keys or certificates in X509. |
| private static byte[] | |
| private static void | |
| private static byte[] | Returns: The concatenated arrayThe first array first, final byte[] The second array second)Concatenate two byte arrays |