- java.lang.Object
- 
- io.helidon.common.crypto.SymmetricCipher
 
- 
- All Implemented Interfaces:
- CommonCipher
 
 public class SymmetricCipher extends Object implements 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.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classSymmetricCipher.BuilderBuilder of theSymmetricCipher.
 - 
Field SummaryFields Modifier and Type Field Description static StringALGORITHM_AES_CBCAES algorithm with CBC method and PKCS5 padding.static StringALGORITHM_AES_CTRAES algorithm with CTR method and no padding.static StringALGORITHM_AES_GCMAES algorithm with GCM method and no padding.static StringALGORITHM_CHA_CHAChaCha20 encryption algorithm.static StringALGORITHM_CHA_CHA_POLY1305ChaCha20 encryption algorithm with Poly1305 authentication code.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SymmetricCipher.Builderbuilder()Create a new builder.static SymmetricCiphercreate(char[] password)Create a new instance based on the password.Base64Valuedecrypt(Base64Value encrypted)Decrypt encrypted message.static Base64Valuedecrypt(String algorithm, byte[] key, byte[] iv, Base64Value encrypted)Decrypt the message with the usage of provided parameters.static Base64Valuedecrypt(String algorithm, String provider, byte[] key, byte[] iv, Base64Value encrypted)Decrypt the message with the usage of provided parameters.static Base64Valuedecrypt(String algorithm, String provider, byte[] key, AlgorithmParameterSpec params, Base64Value encrypted)Decrypt the message with the usage of provided parameters.Base64Valueencrypt(Base64Value message)Encrypt message.static Base64Valueencrypt(String algorithm, byte[] key, byte[] iv, Base64Value plain)Encrypt the message with the usage of provided parameters.static Base64Valueencrypt(String algorithm, String provider, byte[] key, byte[] iv, Base64Value plain)Encrypt the message with the usage of provided parameters.static Base64Valueencrypt(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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface io.helidon.common.crypto.CommonCipherdecryptFromString, encryptToString
 
- 
 
- 
- 
- 
Field Detail- 
ALGORITHM_AES_CBCpublic static final String 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:
- Constant Field Values
 
 - 
ALGORITHM_AES_CTRpublic static final String 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:
- Constant Field Values
 
 - 
ALGORITHM_AES_GCMpublic static final String 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:
- Constant Field Values
 
 - 
ALGORITHM_CHA_CHApublic static final String ALGORITHM_CHA_CHA ChaCha20 encryption algorithm.
 Value is: "ChaCha20".- See Also:
- Constant Field Values
 
 - 
ALGORITHM_CHA_CHA_POLY1305public static final String ALGORITHM_CHA_CHA_POLY1305 ChaCha20 encryption algorithm with Poly1305 authentication code.
 Value is: "ChaCha20-Poly1305".- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
builderpublic static SymmetricCipher.Builder builder() Create a new builder.- Returns:
- new builder
 
 - 
createpublic static SymmetricCipher create(char[] password) Create a new instance based on the password. Default used algorithm isALGORITHM_AES_GCM.- Parameters:
- password- password
- Returns:
- new instance
 
 - 
encryptpublic static Base64Value encrypt(String algorithm, byte[] key, byte[] iv, Base64Value plain) Encrypt the message with the usage of provided parameters.- Parameters:
- algorithm- algorithm to be used
- key- key to encrypt message
- iv- initialization vector
- plain- message
- Returns:
- encrypted message
 
 - 
encryptpublic 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 used
- provider- provider of the algorithm
- key- key to encrypt message
- iv- initialization vector
- plain- message
- Returns:
- encrypted message
 
 - 
encryptpublic 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 used
- provider- provider of the algorithm
- key- key to encrypt message
- params- cipher parameter object
- plain- message
- Returns:
- encrypted message
 
 - 
decryptpublic static Base64Value decrypt(String algorithm, byte[] key, byte[] iv, Base64Value encrypted) Decrypt the message with the usage of provided parameters.- Parameters:
- algorithm- algorithm to be used
- key- key to decrypt message
- iv- encrypted message initialization vector
- encrypted- encrypted message
- Returns:
- decrypted message
 
 - 
decryptpublic 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 used
- provider- algorithm provider
- key- key to decrypt message
- iv- encrypted message initialization vector
- encrypted- encrypted message
- Returns:
- decrypted message
 
 - 
decryptpublic 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 used
- provider- algorithm provider
- key- key to decrypt message
- params- cipher parameter object
- encrypted- encrypted message
- Returns:
- decrypted message
 
 - 
encryptpublic Base64Value encrypt(Base64Value message) Description copied from interface:CommonCipherEncrypt message.- Specified by:
- encryptin interface- CommonCipher
- Parameters:
- message- message
- Returns:
- encrypted message
 
 - 
decryptpublic Base64Value decrypt(Base64Value encrypted) Description copied from interface:CommonCipherDecrypt encrypted message.- Specified by:
- decryptin interface- CommonCipher
- Parameters:
- encrypted- encrypted message
- Returns:
- decrypted message
 
 
- 
 
-