java.lang.Object
org.seppiko.commons.utils.crypto.spec.ParameterSpecUtil
Parameter Specification implement utility
- Author:
- Leonard Woo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ChaCha20ParameterSpecgetChacha20(byte[] nonce, int counter) ChaCha20ParameterSpec instancestatic DHParameterSpecgetDH(BigInteger p, BigInteger g) DHParameterSpec instancestatic DHParameterSpecgetDH(BigInteger p, BigInteger g, int l) DHParameterSpec instancestatic ECParameterSpecgetEC(ECField field, BigInteger firstCoefficient, BigInteger secondCoefficient, BigInteger affineX, BigInteger affineY, BigInteger generator, int cofactor) ECParameterSpec instancestatic EdDSAParameterSpecgetEdDSA(boolean prehash, byte[] context) Construct anEdDSAParameterSpecby specifying whether the prehash mode is used.static GCMParameterSpecgetGCM(int tLen, byte[] src) GCMParameterSpec instancestatic GCMParameterSpecgetGCM(int tLen, byte[] src, int off, int len) GCMParameterSpec instancestatic IvParameterSpecgetIV(byte[] iv) IvParameterSpec instancestatic IvParameterSpecgetIV(byte[] iv, int off, int len) IvParameterSpec instancestatic OAEPParameterSpecgetOAEP(String mdName, String mgfName, AlgorithmParameterSpec mgfSpec, PSource pSrc) Constructs a parameter set for OAEP padding as defined in the PKCS #1 standard using the specified message digest algorithmmdName, mask generation function algorithmmgfName, parameters for the mask generation functionmgfSpec, and source of the encoding input PpSrc.static PBEParameterSpecgetPBE(byte[] salt, int iterationCount) PBEParameterSpec instancestatic PBEParameterSpecgetPBE(byte[] salt, int iterationCount, AlgorithmParameterSpec paramSpec) PBEParameterSpec objectstatic PSSParameterSpecgetPss(MGF1ParameterSpec mgfSpec, int saltLen) Creates a new PSSParameterSpec as defined in the PKCS #1 standard using the specified message digest.
-
Method Details
-
getGCM
public static GCMParameterSpec getGCM(int tLen, byte[] src) throws NullPointerException, IllegalArgumentException GCMParameterSpec instance- Parameters:
tLen- GCM authentication tag lengthsrc- the IV source buffer- Returns:
- GCMParameterSpec instance
- Throws:
NullPointerException- src is nullIllegalArgumentException- 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 lengthsrc- the IV source bufferoff- the offset in src where the IV startslen- 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
IvParameterSpec instance- Parameters:
iv- the buffer with the IV- Returns:
- IvParameterSpec instance
- Throws:
NullPointerException- if iv is nullIllegalArgumentException- if iv is null or (iv.length - offset < len)ArrayIndexOutOfBoundsException- is thrown if offset or len index bytes outside the iv.- See Also:
-
getIV
IvParameterSpec instance- Parameters:
iv- the buffer with the IVoff- the offset in iv where the IV startslen- 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
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
DHParameterSpec instance- Parameters:
p- the prime modulusg- the base generator- Returns:
- DHParameterSpec instance
- See Also:
-
getDH
DHParameterSpec instance- Parameters:
p- the prime modulusg- the base generatorl- the size in bits of the random exponent (private value)- Returns:
- DHParameterSpec instance
- See Also:
-
getEC
public static ECParameterSpec getEC(ECField field, BigInteger firstCoefficient, BigInteger secondCoefficient, BigInteger affineX, BigInteger affineY, BigInteger generator, int cofactor) throws NullPointerException, IllegalArgumentException ECParameterSpec instance- Parameters:
field- the finite field that this elliptic curve is over.firstCoefficient- the first coefficient of this elliptic curve.secondCoefficient- 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 nullIllegalArgumentException- ifgeneratororcofactoris not positive oraffineXoraffineYis not null and not infield.- See Also:
-
getChacha20
public static ChaCha20ParameterSpec getChacha20(byte[] nonce, int counter) throws NullPointerException, IllegalArgumentException ChaCha20ParameterSpec instance- Parameters:
nonce- a 12-byte nonce valuecounter- the initial counter value- Returns:
- ChaCha20ParameterSpec instance.
- Throws:
NullPointerException-noncemust be notnull.IllegalArgumentException-noncemust 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 algorithmmdName, mask generation function algorithmmgfName, parameters for the mask generation functionmgfSpec, and source of the encoding input PpSrc.- 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- ifmdName,mgfName, orpSrcis null.- See Also:
-
getEdDSA
public static EdDSAParameterSpec getEdDSA(boolean prehash, byte[] context) throws InvalidParameterException Construct anEdDSAParameterSpecby 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.
-
getPss
Creates a new PSSParameterSpec as defined in the PKCS #1 standard using the specified message digest.- Parameters:
mgfSpec- seeMGF1ParameterSpecsaltLen- salt length- Returns:
- A PSSParameterSpec as defined in the PKCS #1
-