Package com.illumon.util.tools
Class PublicPrivateKeyEncryption
java.lang.Object
com.illumon.util.tools.PublicPrivateKeyEncryption
public class PublicPrivateKeyEncryption extends Object
Immutable class to provide simple public/private-key encryption/decryption based on a provided keypair, or encryption based on a provided PublicKey.
Results are provided as a base-64-encoded String. Note that PublicKey instances are serializable and can be provided to a client for encryption.
-
Constructor Summary
Constructors Constructor Description PublicPrivateKeyEncryption(String keyfile)
Initialize the key pair based on the provided key filenamePublicPrivateKeyEncryption(PublicKey publicKey)
Initialize the public key based on the provided PublicKey, and ensure decryption will fail -
Method Summary
Modifier and Type Method Description String
decrypt(String encryptedString)
Decrypt the supplied base-64 encoded, encrypted StringString
encrypt(String stringToEncrypt)
Encrypt and re-encode as base-64 the supplied StringPublicKey
getPublicKey()
Return the public key that can be used for encryption
-
Constructor Details
-
PublicPrivateKeyEncryption
Initialize the key pair based on the provided key filename- Parameters:
keyfile
- the filename (including path) for the public/private keypair
-
PublicPrivateKeyEncryption
Initialize the public key based on the provided PublicKey, and ensure decryption will fail- Parameters:
publicKey
- the public key to be used for the encryption
-
-
Method Details
-
getPublicKey
Return the public key that can be used for encryption- Returns:
- the PublicKey
-
encrypt
Encrypt and re-encode as base-64 the supplied String- Parameters:
stringToEncrypt
- the String to encrypt- Returns:
- a base-64 encoded, encrypted String
-
decrypt
Decrypt the supplied base-64 encoded, encrypted String- Parameters:
encryptedString
- the base-64 encoded, encrypted String- Returns:
- the decrypted String
-