Interface KeyPairResourceWriter<OPTIONS extends PrivateKeyEncryptionContext>
- Type Parameters:
OPTIONS- The type ofPrivateKeyEncryptionContextto use with thisKeyPairResourceWriter.
- All Known Implementing Classes:
OpenSSHKeyPairResourceWriter
public interface KeyPairResourceWriter<OPTIONS extends PrivateKeyEncryptionContext>
A
KeyPairResourceWriter can serialize keys to an external representation.-
Method Summary
Modifier and TypeMethodDescriptionvoidwritePrivateKey(KeyPair key, String comment, OPTIONS options, OutputStream out) Writes a serialization of a private key from a givenKeyPairto a givenOutputStream.default voidwritePublicKey(KeyPair key, String comment, OutputStream out) Writes a serialization of a public key from a givenKeyPairto a givenOutputStream.voidwritePublicKey(PublicKey key, String comment, OutputStream out) Writes a serialization of aPublicKeyto a givenOutputStream.
-
Method Details
-
writePrivateKey
void writePrivateKey(KeyPair key, String comment, OPTIONS options, OutputStream out) throws IOException, GeneralSecurityException Writes a serialization of a private key from a givenKeyPairto a givenOutputStream.- Parameters:
key- to write the private key ofcomment- to write with the private keyoptions- for writing the key; may benullif no encryption is wanted. The caller is responsible for clearing the options when no longer needed. If the passphrase obtained from the context isnullor an empty/blank string (length zero or containing only whitespace), the key is written unencrypted.out- TheOutputStreamto write to - recommend using aSecureByteArrayOutputStreamin order to reduce sensitive data exposure in memory- Throws:
GeneralSecurityException- if the key is inconsistent or unknown, or the encryption specified cannot be appliedIOException- if the key cannot be written
-
writePublicKey
default void writePublicKey(KeyPair key, String comment, OutputStream out) throws IOException, GeneralSecurityException Writes a serialization of a public key from a givenKeyPairto a givenOutputStream.- Parameters:
key- to write the public key ofcomment- to write with the public keyout- TheOutputStreamto write to - recommend using aSecureByteArrayOutputStreamin order to reduce sensitive data exposure in memory- Throws:
GeneralSecurityException- if the key is unknownIOException- if the key cannot be written
-
writePublicKey
void writePublicKey(PublicKey key, String comment, OutputStream out) throws IOException, GeneralSecurityException Writes a serialization of aPublicKeyto a givenOutputStream.- Parameters:
key- to writecomment- to write with the keyout- TheOutputStreamto write to - recommend using aSecureByteArrayOutputStreamin order to reduce sensitive data exposure in memory- Throws:
GeneralSecurityException- if the key is unknownIOException- if the key cannot be written
-