java.lang.Object
org.seppiko.commons.utils.crypto.CryptoUtil
Crypto util
- Author:
- Leonard Woo
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]cipher(String algorithm, String providerName, int opmode, Key key, AlgorithmParameterSpec params, byte[] data) Cipher utilstatic byte[]cipher(String algorithm, Provider provider, int opmode, Key key, AlgorithmParameterSpec params, byte[] data) Cipher utilstatic ProvidergetProvider(String providerName) Check and get provider objectstatic byte[]Mac utilstatic byte[]Message Digest util
-
Field Details
-
NONPROVIDER
Non provider
-
-
Method Details
-
getProvider
Check and get provider object- Parameters:
providerName- the name of the provider.- Returns:
- the provider instance.
If provider name is empty or
nullreturnNONPROVIDER. If provider not found returnNONPROVIDER.
-
cipher
public static byte[] cipher(String algorithm, Provider provider, int opmode, Key key, AlgorithmParameterSpec params, byte[] data) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException Cipher util- Parameters:
algorithm- cipher algorithm.provider- cipher provider, if you do not need this setnullorNONPROVIDER.opmode- cipher mode.key- crypto key.params- Algorithm Parameter Spec, if you do not need this setnull.data- the input data buffer.- Returns:
- the new data buffer with the result.
- Throws:
NoSuchPaddingException- if transformation contains a padding scheme that is not available.NoSuchAlgorithmException- if transformation is null, empty, in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this cipher, or this cipher requires algorithm parameters and params is null, or the given algorithm parameters imply a cryptographic strength that would exceed the legal limits (as determined from the configured jurisdiction policy files).InvalidKeyException- if the given key is inappropriate for initializing this cipher, or its keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).IllegalBlockSizeException- if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided.BadPaddingException- if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes.AEADBadTagException- – if this cipher is decrypting in an AEAD mode (such as GCM/CCM), and the received authentication tag does not match the calculated value.- See Also:
-
cipher
public static byte[] cipher(String algorithm, String providerName, int opmode, Key key, AlgorithmParameterSpec params, byte[] data) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException Cipher util- Parameters:
algorithm- cipher algorithm.providerName- cipher provider name, if you do not need this setnullor"".opmode- cipher mode.key- crypto key.params- Algorithm Parameter Spec, if you do not need this set null.data- the input data buffer.- Returns:
- the new data buffer with the result.
- Throws:
NoSuchPaddingException- if transformation contains a padding scheme that is not available.NoSuchAlgorithmException- if transformation is null, empty, in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.InvalidAlgorithmParameterException- if the given algorithm parameters are inappropriate for this cipher, or this cipher requires algorithm parameters and params is null, or the given algorithm parameters imply a cryptographic strength that would exceed the legal limits (as determined from the configured jurisdiction policy files).InvalidKeyException- if the given key is inappropriate for initializing this cipher, or its keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).IllegalBlockSizeException- if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided.BadPaddingException- if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes.AEADBadTagException- – if this cipher is decrypting in an AEAD mode (such as GCM/CCM), and the received authentication tag does not match the calculated value.- See Also:
-
md
public static byte[] md(String algorithm, Provider provider, byte[] data) throws NoSuchAlgorithmException, NullPointerException Message Digest util- Parameters:
algorithm- Message Digest Algorithm.provider- the provider. if you do not need this setNONPROVIDER.data- raw data.- Returns:
- data hash.
- Throws:
NoSuchAlgorithmException- if no Provider supports a MessageDigestSpi implementation for the specified algorithm.NullPointerException- if algorithm is null.- See Also:
-
mac
public static byte[] mac(String algorithm, Provider provider, String keyAlgorithm, byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException, NullPointerException Mac util- Parameters:
algorithm- mac hash algorithm.provider- the provider. if you do not need this setNONPROVIDER.keyAlgorithm- mac hash key algorithm.data- raw data.key- mac hash key.- Returns:
- data hash.
- Throws:
NoSuchAlgorithmException- if no Provider supports a MacSpi implementation for the specified algorithm.InvalidKeyException- if the given key is inappropriate for initializing this MAC.NullPointerException- if algorithm is null.- See Also:
-