java.lang.Object
org.seppiko.commons.utils.crypto.AsymmetricUtil
- All Implemented Interfaces:
Serializable,Cryptography
Public-key cryptography (aka Asymmetric cryptography) utility
- Author:
- Leonard Woo
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decrypt(byte[] data) Decrypt data with Asymmetric cryptographybyte[]decryptWithPublicKey(byte[] data) Decrypt data with Asymmetric cryptographybyte[]encrypt(byte[] data) Encrypt data with Asymmetric cryptographybyte[]encryptWithPrivateKey(byte[] data) Encrypt data with Asymmetric cryptographyvoidsetKeyPair(PublicKey publicKey, PrivateKey privateKey) Set key-pairvoidvoidsetProvider(Provider provider) Set provider.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.seppiko.commons.utils.crypto.Cryptography
setProvider
-
Constructor Details
-
AsymmetricUtil
Public-key cryptography algorithm- Parameters:
algorithm- Algorithm name.- Throws:
NoSuchAlgorithmException- Algorithm name parser failed.
-
-
Method Details
-
setProvider
Set provider.- Specified by:
setProviderin interfaceCryptography- Parameters:
provider- the provider.
-
setKeyPair
Set key-pair- Parameters:
publicKey- public key.privateKey- private key.- See Also:
-
setParameterSpec
- Specified by:
setParameterSpecin interfaceCryptography- Parameters:
params-AlgorithmParameterSpecsubclass.
-
encrypt
public byte[] encrypt(byte[] data) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, NullPointerException Encrypt data with Asymmetric cryptography- Specified by:
encryptin interfaceCryptography- Parameters:
data- plaintext data buffer- Returns:
- ciphertext data buffer
- Throws:
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).NoSuchPaddingException- if transformation contains a padding scheme that is not available.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.NoSuchAlgorithmException- if transformation is null, empty, in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.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.InvalidKeyException- if the given key is inappropriate for initializing this cipher, or its key-size exceeds the maximum allowable key-size (as determined from the configured jurisdiction policy files).NullPointerException- public key isnull.
-
decrypt
public byte[] decrypt(byte[] data) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, NullPointerException Decrypt data with Asymmetric cryptography- Specified by:
decryptin interfaceCryptography- Parameters:
data- ciphertext data buffer- Returns:
- plaintext data buffer
- Throws:
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).NoSuchPaddingException- if transformation contains a padding scheme that is not available.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.NoSuchAlgorithmException- if transformation is null, empty, in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.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.InvalidKeyException- if the given key is inappropriate for initializing this cipher, or its key-size exceeds the maximum allowable key-size (as determined from the configured jurisdiction policy files).NullPointerException- private key isnull.
-
encryptWithPrivateKey
public byte[] encryptWithPrivateKey(byte[] data) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, NullPointerException Encrypt data with Asymmetric cryptography- Parameters:
data- plaintext data buffer- Returns:
- ciphertext data buffer
- Throws:
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).NoSuchPaddingException- if transformation contains a padding scheme that is not available.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.NoSuchAlgorithmException- if transformation is null, empty, in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.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.InvalidKeyException- if the given key is inappropriate for initializing this cipher, or its key-size exceeds the maximum allowable key-size (as determined from the configured jurisdiction policy files).NullPointerException- private key isnull.
-
decryptWithPublicKey
public byte[] decryptWithPublicKey(byte[] data) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, NullPointerException Decrypt data with Asymmetric cryptography- Parameters:
data- ciphertext data buffer- Returns:
- plaintext data buffer
- Throws:
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).NoSuchPaddingException- if transformation contains a padding scheme that is not available.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.NoSuchAlgorithmException- if transformation is null, empty, in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.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.InvalidKeyException- if the given key is inappropriate for initializing this cipher, or its key-size exceeds the maximum allowable key-size (as determined from the configured jurisdiction policy files).NullPointerException- public key isnull.
-