Class RSAKeys

java.lang.Object
com.atlassian.oauth.util.RSAKeys

public class RSAKeys extends Object
  • Constructor Details

    • RSAKeys

      public RSAKeys()
  • Method Details

    • generateKeyPair

      public static KeyPair generateKeyPair() throws NoSuchAlgorithmException
      Returns a newly created RSA public/private KeyPair.
      Returns:
      newly created RSA public/private KeyPair
      Throws:
      NoSuchAlgorithmException - thrown if there are no RSA providers available
    • fromPemEncodingToPublicKey

      public static PublicKey fromPemEncodingToPublicKey(String pemEncodedPublicKey) throws NoSuchAlgorithmException, InvalidKeySpecException
      Returns the RSA PublicKey that was decoded from the encoded string. The encoded key may contain new-lines and OpenSSL header/footer sections. It must be a public key that has been encoded using the X.509 key spec and base-64 algorithm.
      Parameters:
      pemEncodedPublicKey - A public key that has been X.509 and base-64 encoded
      Returns:
      decoded RSA PublicKey
      Throws:
      NoSuchAlgorithmException - thrown if there are no RSA providers available
      InvalidKeySpecException - thrown if pemEncodedPublicKey is not a validly encoded PublicKey
    • fromEncodedCertificateToPublicKey

      public static PublicKey fromEncodedCertificateToPublicKey(String encodedCertificate) throws CertificateException
      Returns the RSA PublicKey that was decoded from the encoded certificate.
      Parameters:
      encodedCertificate - A public certificate
      Returns:
      the RSA PublicKey that was decoded from the encoded certificate
      Throws:
      CertificateException - throw if the encodedCertificate is not a validly encoded X509Certificate
    • fromPemEncodingToPrivateKey

      public static PrivateKey fromPemEncodingToPrivateKey(String pemEncodedPrivateKey) throws NoSuchAlgorithmException, InvalidKeySpecException
      Returns the RSA PrivateKey that was decoded from the encoded string. The encoded key may contain new-lines and OpenSSL header/footer sections. It must be a private key that has been encoded using the PKCS8 key spec and the base-64 algorithm.
      Parameters:
      pemEncodedPrivateKey - A private key that has been PKCS8 and base-64 encoded
      Returns:
      decoded RSA PrivateKey
      Throws:
      NoSuchAlgorithmException - thrown if there are no RSA providers available
      InvalidKeySpecException - thrown if pemEncodedPrivateKey is not a validly encoded PrivateKey
    • toPemEncoding

      public static String toPemEncoding(Key key)
      Convert the key to the appropriate string encoding. For public keys, this means converting to the X.509 key spec and then encoding in base-64. For private keys, this means converting to the PKCS8 key spec and then encoding in base-64.
      Parameters:
      key - Key to be encoded
      Returns:
      Key as an encoded string
    • convertFromOpenSsl

      public static String convertFromOpenSsl(String key)
      Strips standard header/footer and any newlines.
      Parameters:
      key - key to convert from an OpenSSL format
      Returns:
      key with standard OpenSSL headers and footers and all newlines removed