Class KeyReader


  • public class KeyReader
    extends Object
    author: Pascal Knueppel
    created at: 02.03.2017

    will provide support methods to translate keys to java objects
    • Constructor Detail

      • KeyReader

        public KeyReader()
    • Method Detail

      • readPrivateRSAKey

        public static PrivateKey readPrivateRSAKey​(byte[] privateKey)
        will read a private rsa key from a given byte-array of a PKCS8EncodedKeySpec
        Parameters:
        privateKey - the bytes of the rsa key
        Returns:
        the private-key interface implementation of rsa
        Throws:
        KeyGenerationException - if the private key could not be created from the given byte-array
      • readPublicRSAKey

        public static PublicKey readPublicRSAKey​(byte[] publicKey)
        will read a public rsa key from a given byte-array of a X509EncodedKeySpec
        Parameters:
        publicKey - the bytes of the rsa key
        Returns:
        the public-key interface implementation of rsa
        Throws:
        KeyGenerationException - if the public key could not be created from the given byte-array
      • readX509Certificate

        public static X509Certificate readX509Certificate​(byte[] certificateBytes)
        should read a X509 certificate from the given byte-array
        Parameters:
        certificateBytes - the bytes of the certificate
        Returns:
        the X509 certificate
        Throws:
        CertificateCreationException - if the certificate could not be created from the given data.
      • readX509Certificate

        public static X509Certificate readX509Certificate​(InputStream certificateStream)
        should read a X509 certificate from the given byte-array
        Parameters:
        certificateStream - the certificate inputstream
        Returns:
        the X509 certificate
        Throws:
        CertificateCreationException - if the certificate could not be created from the given data.
      • generateNewRsaKeyPair

        public static KeyPair generateNewRsaKeyPair​(int keyLength)
        Parameters:
        keyLength - the key length of the RSA key that should be generated
        Returns:
        a new rsa keypair with the given length