Package io.mangoo.crypto
Class Crypto
java.lang.Object
io.mangoo.crypto.Crypto
Convenient class for encryption and decryption
- Author:
- svenkubiak
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decrypt(byte[] text, PrivateKey key) Decrypt text using private keyDecrypts a given encrypted text using the application secret property (application.secret) as keyDecrypts a given encrypted text using the given keydecrypt(String text, PrivateKey key) Decrypt Base64 encoded text using private keybyte[]Encrypt a text using public keyEncrypts a given plain text using the application secret property (application.secret) as key Encryption is done by using AES and CBC Cipher and a key length of 256 bitEncrypts a given plain text using the given key Encryption is done by using AES and CBC Cipher and a key length of 256 bitEncrypt a text using public key.Generate key which contains a pair of private and public key using 4096 bytesgetKeyAsString(Key key) Convert a Key to string encoded as Base64Generates Private Key from Base64 encoded stringGenerates Public Key from Base64 encoded stringgetSizedSecret(String secret)
-
Constructor Details
-
Crypto
-
-
Method Details
-
decrypt
Decrypts a given encrypted text using the application secret property (application.secret) as key- Parameters:
encrytedText- The encrypted text- Returns:
- The clear text or null if decryption fails
-
decrypt
Decrypts a given encrypted text using the given key- Parameters:
encrytedText- The encrypted textkey- The encryption key- Returns:
- The clear text or null if decryption fails
-
encrypt
Encrypts a given plain text using the application secret property (application.secret) as key Encryption is done by using AES and CBC Cipher and a key length of 256 bit- Parameters:
plainText- The plain text to encrypt- Returns:
- The encrypted text or null if encryption fails
-
encrypt
Encrypts a given plain text using the given key Encryption is done by using AES and CBC Cipher and a key length of 256 bit- Parameters:
plainText- The plain text to encryptkey- The key to use for encryption- Returns:
- The encrypted text or null if encryption fails
-
getSizedSecret
-
generateKeyPair
Generate key which contains a pair of private and public key using 4096 bytes- Returns:
- key pair
-
encrypt
Encrypt a text using public key- Parameters:
text- The plain textkey- The public key- Returns:
- Encrypted text
- Throws:
MangooEncryptionException- if encryption fails
-
encrypt
Encrypt a text using public key. The result is encoded to Base64.- Parameters:
text- The plain textkey- The public key- Returns:
- Encrypted string as base64
- Throws:
MangooEncryptionException- if encryption fails
-
decrypt
Decrypt text using private key- Parameters:
text- The encrypted textkey- The private key- Returns:
- The unencrypted text
- Throws:
MangooEncryptionException- if decryption fails
-
decrypt
Decrypt Base64 encoded text using private key- Parameters:
text- The encrypted text, encoded as Base64key- The private key- Returns:
- The plain text encoded as UTF8
- Throws:
MangooEncryptionException- if decryption fails
-
getKeyAsString
Convert a Key to string encoded as Base64- Parameters:
key- The key (private or public)- Returns:
- A string representation of the key
-
getPrivateKeyFromString
Generates Private Key from Base64 encoded string- Parameters:
key- Base64 encoded string which represents the key- Returns:
- The PrivateKey
- Throws:
MangooEncryptionException- if getting private key from string fails
-
getPublicKeyFromString
Generates Public Key from Base64 encoded string- Parameters:
key- Base64 encoded string which represents the key- Returns:
- The PublicKey
- Throws:
MangooEncryptionException- if getting public key from string fails
-