Class ParameterSpacUtil

java.lang.Object
org.seppiko.commons.utils.crypto.spec.ParameterSpacUtil

public class ParameterSpacUtil extends Object
Parameter Specification implement util
Author:
Leonard Woo
See Also:
  • Method Details

    • getGCM

      public static GCMParameterSpec getGCM(int tLen, byte[] src) throws NullPointerException, IllegalArgumentException
      GCMParameterSpec instance
      Parameters:
      tLen - GCM authentication tag length
      src - the IV source buffer
      Returns:
      GCMParameterSpec instance
      Throws:
      NullPointerException - src is null
      IllegalArgumentException - if tLen is negative, src is null, len or offset is negative, or the sum of offset and len is greater than the length of the src byte array.
      See Also:
    • getGCM

      public static GCMParameterSpec getGCM(int tLen, byte[] src, int off, int len) throws IllegalArgumentException
      GCMParameterSpec instance
      Parameters:
      tLen - GCM authentication tag length
      src - the IV source buffer
      off - the offset in src where the IV starts
      len - the number of IV bytes
      Returns:
      GCMParameterSpec instance
      Throws:
      IllegalArgumentException - if tLen is negative, src is null, len or offset is negative, or the sum of offset and len is greater than the length of the src byte array.
      See Also:
    • getIV

      public static IvParameterSpec getIV(byte[] iv) throws NullPointerException
      IvParameterSpec instance
      Parameters:
      iv - the buffer with the IV
      Returns:
      IvParameterSpec instance
      Throws:
      NullPointerException - if iv is null
      IllegalArgumentException - if iv is null or (iv.length - offset < len)
      ArrayIndexOutOfBoundsException - is thrown if offset or len index bytes outside the iv.
      See Also:
    • getIV

      public static IvParameterSpec getIV(byte[] iv, int off, int len)
      IvParameterSpec instance
      Parameters:
      iv - the buffer with the IV
      off - the offset in iv where the IV starts
      len - the number of IV bytes
      Returns:
      IvParameterSpec instance
      Throws:
      IllegalArgumentException - if iv is null or (iv.length - offset < len)
      ArrayIndexOutOfBoundsException - is thrown if offset or len index bytes outside the iv.
      See Also:
    • getPBE

      public static PBEParameterSpec getPBE(byte[] salt, int iterationCount) throws NullPointerException
      PBEParameterSpec instance
      Parameters:
      salt - the salt. The contents of salt are copied to protect against subsequent modification.
      iterationCount - the iteration count.
      Returns:
      PBEParameterSpec instance
      Throws:
      NullPointerException - if salt is null
      See Also:
    • getPBE

      public static PBEParameterSpec getPBE(byte[] salt, int iterationCount, AlgorithmParameterSpec paramSpec) throws NullPointerException
      PBEParameterSpec object
      Parameters:
      salt - the salt. The contents of salt are copied to protect against subsequent modification.
      iterationCount - the iteration count.
      paramSpec - the cipher algorithm parameter specification
      Returns:
      PBEParameterSpec instance
      Throws:
      NullPointerException - if salt is null
      See Also:
    • getDH

      public static DHParameterSpec getDH(BigInteger p, BigInteger g)
      DHParameterSpec instance
      Parameters:
      p - the prime modulus
      g - the base generator
      Returns:
      DHParameterSpec instance
      See Also:
    • getDH

      public static DHParameterSpec getDH(BigInteger p, BigInteger g, int l)
      DHParameterSpec instance
      Parameters:
      p - the prime modulus
      g - the base generator
      l - the size in bits of the random exponent (private value)
      Returns:
      DHParameterSpec instance
      See Also:
    • getEC

      public static ECParameterSpec getEC(ECField field, BigInteger fristCoefficient, BigInteger secondfficient, BigInteger affineX, BigInteger affineY, BigInteger generator, int cofactor) throws NullPointerException, IllegalArgumentException
      ECParameterSpec instance
      Parameters:
      field - the finite field that this elliptic curve is over.
      fristCoefficient - the first coefficient of this elliptic curve.
      secondfficient - the second coefficient of this elliptic curve.
      affineX - the affine x-coordinate.
      affineY - the affine y-coordinate.
      generator - the order of the generator.
      cofactor - the cofactor.
      Returns:
      ECParameterSpec instance
      Throws:
      NullPointerException - if same parameter is null
      IllegalArgumentException - if generator or cofactor is not positive or affineX or affineY is not null and not in field.
      See Also:
    • getChacha20

      public static ChaCha20ParameterSpec getChacha20(byte[] nonce, int counter) throws NullPointerException, IllegalArgumentException
      ChaCha20ParameterSpec instance
      Parameters:
      nonce - a 12-byte nonce value
      counter - the initial counter value
      Returns:
      ChaCha20ParameterSpec instance.
      Throws:
      NullPointerException - nonce must be not null.
      IllegalArgumentException - nonce must be 12 bytes in length.
      See Also:
    • getOAEP

      public static OAEPParameterSpec getOAEP(String mdName, String mgfName, AlgorithmParameterSpec mgfSpec, PSource pSrc) throws NullPointerException
      Constructs a parameter set for OAEP padding as defined in the PKCS #1 standard using the specified message digest algorithm mdName, mask generation function algorithm mgfName, parameters for the mask generation function mgfSpec, and source of the encoding input P pSrc.
      Parameters:
      mdName - the algorithm name for the message digest.
      mgfName - the algorithm name for the mask generation function.
      mgfSpec - the parameters for the mask generation function. If null is specified, null will be returned by getMGFParameters().
      pSrc - the source of the encoding input P.
      Returns:
      OAEPParameterSpec instance.
      Throws:
      NullPointerException - if mdName, mgfName, or pSrc is null.
      See Also:
    • getEdDSA

      public static EdDSAParameterSpec getEdDSA(boolean prehash, byte[] context) throws InvalidParameterException
      Construct an EdDSAParameterSpec by specifying whether the prehash mode is used. No context is provided so this constructor specifies a mode in which the context is null. Note that this mode may be different than the mode in which an empty array is used as the context.
      Parameters:
      prehash - whether the prehash mode is specified.
      context - the context is copied and bound to the signature.
      Returns:
      EdDSAParameterSpec instance.
      Throws:
      InvalidParameterException - if context length is greater than 255.