Class OpenSSHKeyPairResourceWriter

    • Constructor Detail

      • OpenSSHKeyPairResourceWriter

        public OpenSSHKeyPairResourceWriter()
    • Method Detail

      • writePrivateKey

        public void writePrivateKey​(java.security.KeyPair key,
                                    java.lang.String comment,
                                    OpenSSHKeyEncryptionContext options,
                                    java.io.OutputStream out)
                             throws java.io.IOException,
                                    java.security.GeneralSecurityException
        Description copied from interface: KeyPairResourceWriter
        Writes a serialization of a private key from a given KeyPair to a given OutputStream.
        Specified by:
        writePrivateKey in interface KeyPairResourceWriter<OpenSSHKeyEncryptionContext>
        Parameters:
        key - to write the private key of
        comment - to write with the private key
        options - for writing the key; may be null if no encryption is wanted. The caller is responsible for clearing the options when no longer needed. If the passphrase obtained from the context is null or an empty/blank string (length zero or containing only whitespace), the key is written unencrypted.
        out - The OutputStream to write to - recommend using a SecureByteArrayOutputStream in order to reduce sensitive data exposure in memory
        Throws:
        java.io.IOException - if the key cannot be written
        java.security.GeneralSecurityException - if the key is inconsistent or unknown, or the encryption specified cannot be applied
      • encodePrivateKey

        public static byte[] encodePrivateKey​(java.security.KeyPair key,
                                              java.lang.String keyType,
                                              int blockSize,
                                              java.lang.String comment)
                                       throws java.io.IOException,
                                              java.security.GeneralSecurityException
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
      • encodePublicKey

        public static byte[] encodePublicKey​(java.security.PublicKey key,
                                             java.lang.String keyType)
                                      throws java.io.IOException,
                                             java.security.GeneralSecurityException
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
      • write

        public static void write​(java.io.OutputStream out,
                                 byte[] bytes,
                                 int lineLength)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • writePublicKey

        public 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 a PublicKey to a given OutputStream. Writes the public key in the single-line OpenSSH format "key-type pub-key comment" without terminating line ending. If the comment has multiple lines, only the first line is written.
        Specified by:
        writePublicKey in interface KeyPairResourceWriter<OpenSSHKeyEncryptionContext>
        Parameters:
        key - to write
        comment - to write with the key
        out - The OutputStream to write to - recommend using a SecureByteArrayOutputStream in order to reduce sensitive data exposure in memory
        Throws:
        java.io.IOException - if the key cannot be written
        java.security.GeneralSecurityException - if the key is unknown
      • firstLine

        public static java.lang.String firstLine​(java.lang.String text)
      • write

        public static void write​(java.io.OutputStream out,
                                 java.lang.String s)
                          throws java.io.IOException
        Throws:
        java.io.IOException