Package convex.core.crypto
Class PEMTools
java.lang.Object
convex.core.crypto.PEMTools
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PrivateKey
decryptPrivateKeyFromPEM
(String pemText, char[] password) Decrypt a PEM string to a private key.static String
encryptPrivateKeyToPEM
(PrivateKey privateKey, char[] password) Encrypt a priavte key into a PEM formated textstatic void
static AKeyPair
Read a key pair from a PEM Stringstatic String
Writes a key pair to a String
-
Constructor Details
-
PEMTools
public PEMTools()
-
-
Method Details
-
writePEM
Writes a key pair to a String- Parameters:
kp
- Key pair to write- Returns:
- PEM String representation of key pair
-
readPEM
Read a key pair from a PEM String- Parameters:
pem
- PEM String- Returns:
- Key pair instance
- Throws:
GeneralSecurityException
- If a security error occurs
-
encryptPrivateKeyToPEM
Encrypt a priavte key into a PEM formated text- Parameters:
privateKey
- Private key to encryptpassword
- Password to use for encryption- Returns:
- PEM text that can be saved or sent to another keystore
- Throws:
Error
- Any encryption error that occurs
-
decryptPrivateKeyFromPEM
Decrypt a PEM string to a private key. The PEM string must contain the "ENCRYPTED PRIVATE KEY" type.- Parameters:
pemText
- PEM string to decodepassword
- Password that was used to encrypt the private key- Returns:
- PrivateKey stored in the PEM
- Throws:
Error
- on reading the PEM, decryption and decoding the private key
-
main
- Throws:
Exception
-