Class RSAPEMResourceKeyPairParser

    • Field Detail

      • BEGINNERS

        public static final java.util.List<java.lang.String> BEGINNERS
      • ENDERS

        public static final java.util.List<java.lang.String> ENDERS
    • Constructor Detail

      • RSAPEMResourceKeyPairParser

        public RSAPEMResourceKeyPairParser()
    • Method Detail

      • extractKeyPairs

        public java.util.Collection<java.security.KeyPair> extractKeyPairs​(SessionContext session,
                                                                           NamedResource resourceKey,
                                                                           java.lang.String beginMarker,
                                                                           java.lang.String endMarker,
                                                                           FilePasswordProvider passwordProvider,
                                                                           java.io.InputStream stream,
                                                                           java.util.Map<java.lang.String,​java.lang.String> headers)
                                                                    throws java.io.IOException,
                                                                           java.security.GeneralSecurityException
        Specified by:
        extractKeyPairs in class AbstractKeyPairResourceParser
        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).
        resourceKey - A hint as to the origin of the text lines
        beginMarker - The line containing the begin marker
        endMarker - The line containing the end marker
        passwordProvider - The FilePasswordProvider to use in case the data is encrypted - may be null if no encrypted
        stream - The decoded data InputStream
        headers - Any headers that may have been available when data was read
        Returns:
        The extracted KeyPairs - may be null/empty if none.
        Throws:
        java.io.IOException - If failed to parse the data
        java.security.GeneralSecurityException - If failed to generate the keys
      • decodeRSAKeyPair

        public static java.security.KeyPair decodeRSAKeyPair​(java.security.KeyFactory kf,
                                                             java.io.InputStream s,
                                                             boolean okToClose)
                                                      throws java.io.IOException,
                                                             java.security.GeneralSecurityException

        The ASN.1 syntax for the private key as per RFC-3447 section A.1.2:

         
         RSAPrivateKey ::= SEQUENCE {
           version           Version,
           modulus           INTEGER,  -- n
           publicExponent    INTEGER,  -- e
           privateExponent   INTEGER,  -- d
           prime1            INTEGER,  -- p
           prime2            INTEGER,  -- q
           exponent1         INTEGER,  -- d mod (p-1)
           exponent2         INTEGER,  -- d mod (q-1)
           coefficient       INTEGER,  -- (inverse of q) mod p
           otherPrimeInfos   OtherPrimeInfos OPTIONAL
         }
         
         
        Parameters:
        kf - The KeyFactory To use to generate the keys
        s - The InputStream containing the encoded bytes
        okToClose - true if the method may close the input stream regardless of success or failure
        Returns:
        The recovered KeyPair
        Throws:
        java.io.IOException - If failed to read or decode the bytes
        java.security.GeneralSecurityException - If failed to generate the keys