Class PrivateKeyUtils

java.lang.Object
se.swedenconnect.security.credential.utils.PrivateKeyUtils

public class PrivateKeyUtils extends Object
Utility methods for handling private keys.
Author:
Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
  • Method Details

    • decodePrivateKey

      public static PrivateKey decodePrivateKey(byte[] bytes) throws KeyException
      Decodes a private key in DER, PEM, and unencrypted PKCS#8 formats.
      Parameters:
      bytes - the key bytes
      Returns:
      the decoded private key
      Throws:
      KeyException - for decoding errors
    • decodePrivateKey

      public static PrivateKey decodePrivateKey(InputStream stream) throws KeyException
      Decodes a private key in DER, PEM, and unencrypted PKCS#8 formats.

      The method does not close the input stream.

      Parameters:
      stream - the input stream
      Returns:
      the decoded private key
      Throws:
      KeyException - for decoding errors
    • decodePrivateKey

      public static PrivateKey decodePrivateKey(Resource resource) throws KeyException
      Decodes a private key in DER, PEM, and unencrypted PKCS#8 formats.
      Parameters:
      resource - the resource
      Returns:
      the decoded private key
      Throws:
      KeyException - for decoding errors