Class AsymmetricUtil

java.lang.Object
org.seppiko.commons.utils.crypto.AsymmetricUtil

public class AsymmetricUtil extends Object
Public-key cryptography aka Asymmetric cryptography util
Author:
Leonard Woo
See Also:
  • Constructor Details

    • AsymmetricUtil

      public AsymmetricUtil(String algorithm)
      Public-key cryptography algorithm
      Parameters:
      algorithm - Algorithm name
  • Method Details

    • setProvider

      public void setProvider(Provider provider)
      set provider
      Parameters:
      provider - provider
    • setKeyPair

      public void setKeyPair(PublicKey publicKey, PrivateKey privateKey)
      set key pair
      Parameters:
      publicKey - public key
      privateKey - private key
      See Also:
    • setParameterSpec

      public void setParameterSpec(AlgorithmParameterSpec params)
      set ParameterSpec
      Parameters:
      params - ParameterSpec
    • encrypt

      Encrypt data with Asymmetric cryptography
      Parameters:
      data - Raw data
      Returns:
      Cryptography
      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 keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).
      NullPointerException - public key is null.
    • decrypt

      Decrypt data with Asymmetric cryptography
      Parameters:
      data - Cryptography
      Returns:
      Raw data
      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 keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).
      NullPointerException - private key is null.
    • encryptWithPrivateKey

      Encrypt data with Asymmetric cryptography
      Parameters:
      data - Raw data
      Returns:
      Cryptography
      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 keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).
      NullPointerException - private key is null.
    • decryptWithPublicKey

      Decrypt data with Asymmetric cryptography
      Parameters:
      data - Cryptography
      Returns:
      Raw data
      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 keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).
      NullPointerException - public key is null.