java.lang.Object
io.helidon.common.crypto.SymmetricCipher
- All Implemented Interfaces:
CommonCipher
This class provides simple and stateless way to encrypt and decrypt messages using selected symmetric cipher.
It requires to have base password provided. Unique cryptography key is generated by this implementation every time it encrypts and decrypts. The key uniqueness is ensured by randomly generated salt which is added to the password.
It requires to have base password provided. Unique cryptography key is generated by this implementation every time it encrypts and decrypts. The key uniqueness is ensured by randomly generated salt which is added to the password.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
AES algorithm with CBC method and PKCS5 padding.static final String
AES algorithm with CTR method and no padding.static final String
AES algorithm with GCM method and no padding.static final String
ChaCha20 encryption algorithm.static final String
ChaCha20 encryption algorithm with Poly1305 authentication code. -
Method Summary
Modifier and TypeMethodDescriptionstatic SymmetricCipher.Builder
builder()
Create a new builder.static SymmetricCipher
create
(char[] password) Create a new instance based on the password.decrypt
(Base64Value encrypted) Decrypt encrypted message.static Base64Value
decrypt
(String algorithm, byte[] key, byte[] iv, Base64Value encrypted) Decrypt the message with the usage of provided parameters.static Base64Value
decrypt
(String algorithm, String provider, byte[] key, byte[] iv, Base64Value encrypted) Decrypt the message with the usage of provided parameters.static Base64Value
decrypt
(String algorithm, String provider, byte[] key, AlgorithmParameterSpec params, Base64Value encrypted) Decrypt the message with the usage of provided parameters.encrypt
(Base64Value message) Encrypt message.static Base64Value
encrypt
(String algorithm, byte[] key, byte[] iv, Base64Value plain) Encrypt the message with the usage of provided parameters.static Base64Value
encrypt
(String algorithm, String provider, byte[] key, byte[] iv, Base64Value plain) Encrypt the message with the usage of provided parameters.static Base64Value
encrypt
(String algorithm, String provider, byte[] key, AlgorithmParameterSpec params, Base64Value plain) Encrypt the message with the usage of provided parameters.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.helidon.common.crypto.CommonCipher
decryptFromString, encryptToString
-
Field Details
-
ALGORITHM_AES_CBC
AES algorithm with CBC method and PKCS5 padding.
It is strongly advised to be used together with HMAC or other authenticated message digest.
Value is: "AES/CBC/PKCS5Padding".- See Also:
-
ALGORITHM_AES_CTR
AES algorithm with CTR method and no padding.
It is strongly advised to be used together with HMAC or other authenticated message digest.
Value is: "AES/CTR/NoPadding".- See Also:
-
ALGORITHM_AES_GCM
AES algorithm with GCM method and no padding.
Does not need to be used with any authenticated message digest since GCM is making its signature by the design.
Value is: "AES/GCM/NoPadding".- See Also:
-
ALGORITHM_CHA_CHA
ChaCha20 encryption algorithm.
Value is: "ChaCha20".- See Also:
-
ALGORITHM_CHA_CHA_POLY1305
ChaCha20 encryption algorithm with Poly1305 authentication code.
Value is: "ChaCha20-Poly1305".- See Also:
-
-
Method Details
-
builder
Create a new builder.- Returns:
- new builder
-
create
Create a new instance based on the password. Default used algorithm isALGORITHM_AES_GCM
.- Parameters:
password
- password- Returns:
- new instance
-
encrypt
Encrypt the message with the usage of provided parameters.- Parameters:
algorithm
- algorithm to be usedkey
- key to encrypt messageiv
- initialization vectorplain
- message- Returns:
- encrypted message
-
encrypt
public static Base64Value encrypt(String algorithm, String provider, byte[] key, byte[] iv, Base64Value plain) Encrypt the message with the usage of provided parameters.- Parameters:
algorithm
- algorithm to be usedprovider
- provider of the algorithmkey
- key to encrypt messageiv
- initialization vectorplain
- message- Returns:
- encrypted message
-
encrypt
public static Base64Value encrypt(String algorithm, String provider, byte[] key, AlgorithmParameterSpec params, Base64Value plain) Encrypt the message with the usage of provided parameters.- Parameters:
algorithm
- algorithm to be usedprovider
- provider of the algorithmkey
- key to encrypt messageparams
- cipher parameter objectplain
- message- Returns:
- encrypted message
-
decrypt
Decrypt the message with the usage of provided parameters.- Parameters:
algorithm
- algorithm to be usedkey
- key to decrypt messageiv
- encrypted message initialization vectorencrypted
- encrypted message- Returns:
- decrypted message
-
decrypt
public static Base64Value decrypt(String algorithm, String provider, byte[] key, byte[] iv, Base64Value encrypted) Decrypt the message with the usage of provided parameters.- Parameters:
algorithm
- algorithm to be usedprovider
- algorithm providerkey
- key to decrypt messageiv
- encrypted message initialization vectorencrypted
- encrypted message- Returns:
- decrypted message
-
decrypt
public static Base64Value decrypt(String algorithm, String provider, byte[] key, AlgorithmParameterSpec params, Base64Value encrypted) Decrypt the message with the usage of provided parameters.- Parameters:
algorithm
- algorithm to be usedprovider
- algorithm providerkey
- key to decrypt messageparams
- cipher parameter objectencrypted
- encrypted message- Returns:
- decrypted message
-
encrypt
Description copied from interface:CommonCipher
Encrypt message.- Specified by:
encrypt
in interfaceCommonCipher
- Parameters:
message
- message- Returns:
- encrypted message
-
decrypt
Description copied from interface:CommonCipher
Decrypt encrypted message.- Specified by:
decrypt
in interfaceCommonCipher
- Parameters:
encrypted
- encrypted message- Returns:
- decrypted message
-