Package com.illumon.util.tools
Class PublicPrivateKeyEncryption
java.lang.Object
com.illumon.util.tools.PublicPrivateKeyEncryption
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPublicPrivateKeyEncryption
(String keyfile) Initialize the key pair based on the provided key filenamePublicPrivateKeyEncryption
(String keyfile, PublicPrivateKeyEncryption.Source source) 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 TypeMethodDescriptionDecrypt the supplied base-64 encoded, encrypted StringEncrypt and re-encode as base-64 the supplied StringReturn 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 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
-