Interface PrivateKeyEntryDecoder<PUB extends java.security.PublicKey,​PRV extends java.security.PrivateKey>

    • Method Detail

      • resolve

        default java.security.PrivateKey resolve​(SessionContext session,
                                                 java.lang.String keyType,
                                                 byte[] keyData)
                                          throws java.io.IOException,
                                                 java.security.GeneralSecurityException
        Specified by:
        resolve in interface PrivateKeyEntryResolver
        Parameters:
        session - The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
        keyType - The OpenSSH reported key type
        keyData - The OpenSSH encoded key data
        Returns:
        The extracted PrivateKey - ignored if null
        Throws:
        java.io.IOException - If failed to parse the key data
        java.security.GeneralSecurityException - If failed to generate the key
      • decodePrivateKey

        default PRV decodePrivateKey​(SessionContext session,
                                     FilePasswordProvider passwordProvider,
                                     byte... keyData)
                              throws java.io.IOException,
                                     java.security.GeneralSecurityException
        Parameters:
        session - The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
        passwordProvider - The FilePasswordProvider to use in case the data is encrypted - may be null if no encrypted data is expected
        keyData - The key data bytes in OpenSSH format (after BASE64 decoding) - ignored if null/empty
        Returns:
        The decoded PrivateKey - or null if no data
        Throws:
        java.io.IOException - If failed to decode the key
        java.security.GeneralSecurityException - If failed to generate the key
      • decodePrivateKey

        default PRV decodePrivateKey​(SessionContext session,
                                     FilePasswordProvider passwordProvider,
                                     byte[] keyData,
                                     int offset,
                                     int length)
                              throws java.io.IOException,
                                     java.security.GeneralSecurityException
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
      • decodePrivateKey

        default PRV decodePrivateKey​(SessionContext session,
                                     FilePasswordProvider passwordProvider,
                                     java.io.InputStream keyData)
                              throws java.io.IOException,
                                     java.security.GeneralSecurityException
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
      • decodePrivateKey

        PRV decodePrivateKey​(SessionContext session,
                             java.lang.String keyType,
                             FilePasswordProvider passwordProvider,
                             java.io.InputStream keyData)
                      throws java.io.IOException,
                             java.security.GeneralSecurityException
        Parameters:
        session - The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
        keyType - The reported / encode key type
        passwordProvider - The FilePasswordProvider to use in case the data is encrypted - may be null if no encrypted data is expected
        keyData - The key data bytes stream positioned after the key type decoding and making sure it is one of the supported types
        Returns:
        The decoded PrivateKey
        Throws:
        java.io.IOException - If failed to read from the data stream
        java.security.GeneralSecurityException - If failed to generate the key
      • encodePrivateKey

        default java.lang.String encodePrivateKey​(SecureByteArrayOutputStream s,
                                                  PRV key,
                                                  PUB pubKey)
                                           throws java.io.IOException
        Encodes the PrivateKey using the OpenSSH format - same one used by the decodePublicKey method(s)
        Parameters:
        s - The SecureByteArrayOutputStream to write the data to.
        key - The PrivateKey - may not be null
        pubKey - The PublicKey belonging to the private key - must be non-null if public key recovery is not supported
        Returns:
        The key type value - one of the KeyTypeNamesSupport.getSupportedKeyTypes() or null if encoding not supported
        Throws:
        java.io.IOException - If failed to generate the encoding
      • isPublicKeyRecoverySupported

        default boolean isPublicKeyRecoverySupported()
      • recoverPublicKey

        default PUB recoverPublicKey​(PRV prvKey)
                              throws java.security.GeneralSecurityException
        Attempts to recover the public key given the private one
        Parameters:
        prvKey - The PrivateKey
        Returns:
        The recovered PublicKey - null if cannot recover it
        Throws:
        java.security.GeneralSecurityException - If failed to generate the public key