Class AbstractKeyConverter

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String NL  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractKeyConverter​(java.lang.String provider, java.lang.String type, int defaultSize)
      Constructor for AbstractKeyConverter
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String formatPrivateKey​(java.security.PrivateKey privateKey)
      Formats a private key to a well formed private key, which is bounded at the beginning by -----BEGIN ...
      java.security.KeyPair generateKeyPair()
      Generates a KeyPair containing a Private- and PublicKey
      java.security.KeyPair generateKeyPair​(java.lang.String algorithm, int keySize)
      Generates a KeyPair containing a Private- and PublicKey
      java.security.PrivateKey getPrivateKey​(byte[] content)
      Reads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by -----BEGIN ...
      java.security.PrivateKey getPrivateKey​(java.io.File file)
      Reads PKCS#8 formated private key from a file, which are each bounded at the beginning by -----BEGIN ...
      java.security.PrivateKey getPrivateKey​(java.lang.String content)
      Reads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by -----BEGIN ...
      java.lang.String getProvider()
      Get the provider
      java.security.PublicKey getPublicKey​(java.io.File file)
      Reads PKCS#8 formated public key from a file, which are each bounded at the beginning by -----BEGIN ...
      java.security.PublicKey getPublicKey​(java.lang.String content)
      Reads PKCS#8 formated public key from a buffer which are each bounded at the beginning by -----BEGIN PUBLIC KEY-----, and bounded at the end by -----END PUBLIC KEY-----.
      java.lang.String getType()
      Get the type, e.g.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractKeyConverter

        protected AbstractKeyConverter​(java.lang.String provider,
                                       java.lang.String type,
                                       int defaultSize)
        Constructor for AbstractKeyConverter
        Parameters:
        provider - the provider
        type - the type
        defaultSize - the default size
    • Method Detail

      • generateKeyPair

        public java.security.KeyPair generateKeyPair()
                                              throws java.security.GeneralSecurityException
        Description copied from interface: IKeyConverter
        Generates a KeyPair containing a Private- and PublicKey
        Specified by:
        generateKeyPair in interface IKeyConverter
        Returns:
        the created KeyPair
        Throws:
        java.security.GeneralSecurityException - in case of error
        See Also:
        IKeyConverter.generateKeyPair()
      • generateKeyPair

        public java.security.KeyPair generateKeyPair​(java.lang.String algorithm,
                                                     int keySize)
                                              throws java.security.GeneralSecurityException
        Description copied from interface: IKeyConverter
        Generates a KeyPair containing a Private- and PublicKey
        Specified by:
        generateKeyPair in interface IKeyConverter
        Parameters:
        algorithm - the algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        keySize - the size of the key
        Returns:
        the created KeyPair
        Throws:
        java.security.GeneralSecurityException - in case of error
        See Also:
        IKeyConverter.generateKeyPair(java.lang.String, int)
      • getPublicKey

        public java.security.PublicKey getPublicKey​(java.lang.String content)
                                             throws java.io.IOException,
                                                    java.security.GeneralSecurityException
        Description copied from interface: IKeyConverter
        Reads PKCS#8 formated public key from a buffer which are each bounded at the beginning by -----BEGIN PUBLIC KEY-----, and bounded at the end by -----END PUBLIC KEY-----.
        Specified by:
        getPublicKey in interface IKeyConverter
        Parameters:
        content - the content
        Returns:
        the public key
        Throws:
        java.io.IOException - in case of error
        java.security.GeneralSecurityException - in case of error
        See Also:
        IKeyConverter.getPublicKey(java.lang.String)
      • getPublicKey

        public java.security.PublicKey getPublicKey​(java.io.File file)
                                             throws java.io.IOException,
                                                    java.security.GeneralSecurityException
        Description copied from interface: IKeyConverter
        Reads PKCS#8 formated public key from a file, which are each bounded at the beginning by -----BEGIN ... PUBLIC KEY-----, and bounded at the end by -----END ... PUBLIC KEY-----.
        Specified by:
        getPublicKey in interface IKeyConverter
        Parameters:
        file - the file to read
        Returns:
        the private key
        Throws:
        java.io.IOException - in case of error
        java.security.GeneralSecurityException - in case of error
        See Also:
        IKeyConverter.getPublicKey(java.io.File)
      • getPrivateKey

        public java.security.PrivateKey getPrivateKey​(byte[] content)
                                               throws java.io.IOException,
                                                      java.security.GeneralSecurityException
        Description copied from interface: IKeyConverter
        Reads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by -----BEGIN ... PRIVATE KEY-----, and bounded at the end by -----END ... PRIVATE KEY-----.
        Specified by:
        getPrivateKey in interface IKeyConverter
        Parameters:
        content - the private key to encode
        Returns:
        the private key
        Throws:
        java.io.IOException - in case of error
        java.security.GeneralSecurityException - in case of error
        See Also:
        IKeyConverter.getPrivateKey(byte[])
      • getPrivateKey

        public java.security.PrivateKey getPrivateKey​(java.lang.String content)
                                               throws java.security.GeneralSecurityException
        Description copied from interface: IKeyConverter
        Reads PKCS#8 formated private key from a buffer, which are each bounded at the beginning by -----BEGIN ... PRIVATE KEY-----, and bounded at the end by -----END ... PRIVATE KEY-----.
        Specified by:
        getPrivateKey in interface IKeyConverter
        Parameters:
        content - the private key to encode
        Returns:
        the private key
        Throws:
        java.security.GeneralSecurityException - in case of error
        See Also:
        IKeyConverter.getPrivateKey(java.lang.String)
      • getPrivateKey

        public java.security.PrivateKey getPrivateKey​(java.io.File file)
                                               throws java.io.IOException,
                                                      java.security.GeneralSecurityException
        Description copied from interface: IKeyConverter
        Reads PKCS#8 formated private key from a file, which are each bounded at the beginning by -----BEGIN ... PRIVATE KEY-----, and bounded at the end by -----END ... PRIVATE KEY-----.
        Specified by:
        getPrivateKey in interface IKeyConverter
        Parameters:
        file - the file to read
        Returns:
        the private key
        Throws:
        java.io.IOException - in case of error
        java.security.GeneralSecurityException - in case of error
        See Also:
        IKeyConverter.getPrivateKey(java.io.File)
      • formatPrivateKey

        public java.lang.String formatPrivateKey​(java.security.PrivateKey privateKey)
        Description copied from interface: IKeyConverter
        Formats a private key to a well formed private key, which is bounded at the beginning by -----BEGIN ... PRIVATE KEY-----, and bounded at the end by -----END ... PRIVATE KEY-----.
        Specified by:
        formatPrivateKey in interface IKeyConverter
        Parameters:
        privateKey - the private key to format
        Returns:
        the well formed certificate
        See Also:
        IKeyConverter.formatPrivateKey(java.security.PrivateKey)