Package oracle.nosql.driver.iam.pki
Class Pem
java.lang.Object
oracle.nosql.driver.iam.pki.Pem
Services for working with PEM encoded private keys, public keys and certificates.
Read a public key
PublicKey readPublicKey(Path path) { try (ReadableByteChannel pem = Files.newByteChannel(path)) { return Pem.decoder() .decodePublicKey(pem); } }Read an unencrypted private key
PrivateKey readPrivateKey(Path path) { try (ReadableByteChannel pem = Files.newByteChannel(path)) { return Pem.decoder() .decodePrivateKey(pem); } }Read an encrypted private key
PrivateKey readPrivateKey(Path path, char[] passphrase) { try (ReadableByteChannel pem = Files.newByteChannel(path)) { return Pem.decoder() .with(passphrase) .decodePrivateKey(pem); } }Write a public key
void writePublicKey(Path path,final PublicKey publicKey) { try (WritableByteChannel pem = Files.newByteChannel(path)) { return Pem.encoder() .write(pem,publicKey); } }Write an unencrypted private key
void writePrivateKey(Path path,final PrivateKey privateKey) { try (WritableByteChannel pem = Files.newByteChannel(path)) { return Pem.encoder() .write(pem,privateKey); } }Write an encrypted private key in PKCS1 format
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); } }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Decodes PEM encoded text streams into the desired formatstatic class
Encode certificates, public keys and private keys into PEM encoded formatstatic class
Configures how private keys are encryptedstatic enum
Denotes the specific syntax used for encoding public and private keys (Does not affect the encoding of certificates)static interface
Holds a passphrase using a try-with-resources model to assure the passphrase plain-text is erased once it has been used -
Method Summary
Modifier and TypeMethodDescriptionstatic Pem.Decoder
decoder()
Return a decoder for certificates, public keys and unencrypted private keys.static Pem.Encoder
encoder()
Return an encoder that does not encrypt private keys and formats private keys in PKCS8, and public keys or certificates in X509.
-
Method Details
-
encoder
Return an encoder that does not encrypt private keys and formats private keys in PKCS8, and public keys or certificates in X509.To encode encrypted private keys call
Pem.Encoder.with(Encryption)
To format private keys and public keys in PKCS1, call
Pem.Encoder.with(Format)
e.g.:Pem.Encoder encoder = Pem.encoder().with(Format.LEGACY);
- Returns:
- Encoder instance
-
decoder
Return a decoder for certificates, public keys and unencrypted private keys.To decode encrypted private keys call
Pem.Decoder.with(Passphrase)
.- Returns:
- Decoder instance
-