Interface KeyPairResourceWriter<OPTIONS extends PrivateKeyEncryptionContext>
-
- Type Parameters:
OPTIONS
- The type ofPrivateKeyEncryptionContext
to use with thisKeyPairResourceWriter
.
- All Known Implementing Classes:
OpenSSHKeyPairResourceWriter
public interface KeyPairResourceWriter<OPTIONS extends PrivateKeyEncryptionContext>
AKeyPairResourceWriter
can serialize keys to an external representation.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
writePrivateKey(java.security.KeyPair key, java.lang.String comment, OPTIONS options, java.io.OutputStream out)
Writes a serialization of a private key from a givenKeyPair
to a givenOutputStream
.default void
writePublicKey(java.security.KeyPair key, java.lang.String comment, java.io.OutputStream out)
Writes a serialization of a public key from a givenKeyPair
to a givenOutputStream
.void
writePublicKey(java.security.PublicKey key, java.lang.String comment, java.io.OutputStream out)
Writes a serialization of aPublicKey
to a givenOutputStream
.
-
-
-
Method Detail
-
writePrivateKey
void writePrivateKey(java.security.KeyPair key, java.lang.String comment, OPTIONS options, java.io.OutputStream out) throws java.io.IOException, java.security.GeneralSecurityException
Writes a serialization of a private key from a givenKeyPair
to a givenOutputStream
.- Parameters:
key
- to write the private key ofcomment
- to write with the private keyoptions
- for writing the key; may benull
if no encryption is wanted. The caller is responsible for clearing the options when no longer needed. If the passphrase obtained from the context isnull
or an empty/blank string (length zero or containing only whitespace), the key is written unencrypted.out
- TheOutputStream
to write to - recommend using aSecureByteArrayOutputStream
in order to reduce sensitive data exposure in memory- Throws:
java.security.GeneralSecurityException
- if the key is inconsistent or unknown, or the encryption specified cannot be appliedjava.io.IOException
- if the key cannot be written
-
writePublicKey
default void writePublicKey(java.security.KeyPair key, java.lang.String comment, java.io.OutputStream out) throws java.io.IOException, java.security.GeneralSecurityException
Writes a serialization of a public key from a givenKeyPair
to a givenOutputStream
.- Parameters:
key
- to write the public key ofcomment
- to write with the public keyout
- TheOutputStream
to write to - recommend using aSecureByteArrayOutputStream
in order to reduce sensitive data exposure in memory- Throws:
java.security.GeneralSecurityException
- if the key is unknownjava.io.IOException
- if the key cannot be written
-
writePublicKey
void writePublicKey(java.security.PublicKey key, java.lang.String comment, java.io.OutputStream out) throws java.io.IOException, java.security.GeneralSecurityException
Writes a serialization of aPublicKey
to a givenOutputStream
.- Parameters:
key
- to writecomment
- to write with the keyout
- TheOutputStream
to write to - recommend using aSecureByteArrayOutputStream
in order to reduce sensitive data exposure in memory- Throws:
java.security.GeneralSecurityException
- if the key is unknownjava.io.IOException
- if the key cannot be written
-
-