Package com.atlassian.oauth.util
Class RSAKeys
java.lang.Object
com.atlassian.oauth.util.RSAKeys
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertFromOpenSsl(String key) Strips standard header/footer and any newlines.static PublicKeyfromEncodedCertificateToPublicKey(String encodedCertificate) Returns the RSAPublicKeythat was decoded from the encoded certificate.static PrivateKeyfromPemEncodingToPrivateKey(String pemEncodedPrivateKey) Returns the RSAPrivateKeythat was decoded from the encoded string.static PublicKeyfromPemEncodingToPublicKey(String pemEncodedPublicKey) Returns the RSAPublicKeythat was decoded from the encoded string.static KeyPairReturns a newly created RSA public/privateKeyPair.static StringtoPemEncoding(Key key) Convert the key to the appropriate string encoding.
-
Constructor Details
-
RSAKeys
public RSAKeys()
-
-
Method Details
-
generateKeyPair
Returns a newly created RSA public/privateKeyPair.- 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 RSAPublicKeythat 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 availableInvalidKeySpecException- thrown ifpemEncodedPublicKeyis not a validly encodedPublicKey
-
fromEncodedCertificateToPublicKey
public static PublicKey fromEncodedCertificateToPublicKey(String encodedCertificate) throws CertificateException Returns the RSAPublicKeythat was decoded from the encoded certificate.- Parameters:
encodedCertificate- A public certificate- Returns:
- the RSA
PublicKeythat was decoded from the encoded certificate - Throws:
CertificateException- throw if theencodedCertificateis not a validly encodedX509Certificate
-
fromPemEncodingToPrivateKey
public static PrivateKey fromPemEncodingToPrivateKey(String pemEncodedPrivateKey) throws NoSuchAlgorithmException, InvalidKeySpecException Returns the RSAPrivateKeythat 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 availableInvalidKeySpecException- thrown ifpemEncodedPrivateKeyis not a validly encodedPrivateKey
-
toPemEncoding
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-Keyto be encoded- Returns:
Keyas an encoded string
-
convertFromOpenSsl
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
-