java.lang.Object
org.seppiko.commons.utils.crypto.spec.KeySpecUtil
Key Specification implement util
- Author:
- Leonard Woo
-
Method Summary
Modifier and TypeMethodDescriptionstatic PrivateKeygenPrivateKey(KeyFactory keyFactory, PKCS8EncodedKeySpec keySpec) Convert PKC8 to private keystatic PublicKeygenPublicKey(KeyFactory keyFactory, X509EncodedKeySpec keySpec) Convert X509 to public keystatic PBEKeySpecgetPBE(char[] password) PBEKeySpec objectstatic PBEKeySpecgetPBE(char[] password, byte[] salt, int iterationCount, int keyLength) PBEKeySpec objectstatic PKCS8EncodedKeySpecgetPKCS8(byte[] key) PKCS8EncodedKeySpec objectstatic PKCS8EncodedKeySpecPKCS8EncodedKeySpec objectstatic SecretKeySpecSecretKeySpec objectstatic SecretKeySpecSecretKeySpec objectstatic X509EncodedKeySpecgetX509(byte[] key) X509EncodedKeySpec objectstatic X509EncodedKeySpecX509EncodedKeySpec objectstatic XECPublicKeySpecgetXECPub(AlgorithmParameterSpec paramSpec, BigInteger u) Construct a public key spec using the supplied parameters and u coordinate.
-
Method Details
-
getSecret
public static SecretKeySpec getSecret(byte[] key, String algorithm) throws NullPointerException, IllegalArgumentException SecretKeySpec object- Parameters:
key- the key material of the secret keyalgorithm- the name of the secret-key algorithm to be associated with the given key material- Returns:
- SecretKeySpec object
- Throws:
NullPointerException- if key is null.IllegalArgumentException- if key is empty, or too short, i.e. key.length-offset<len.- See Also:
-
getSecret
public static SecretKeySpec getSecret(byte[] key, int off, int len, String algorithm) throws NullPointerException, IllegalArgumentException SecretKeySpec object- Parameters:
key- the key material of the secret keyoff- the offset in key where the key material startslen- the length of the key materialalgorithm- the name of the secret-key algorithm to be associated with the given key material- Returns:
- SecretKeySpec object
- Throws:
NullPointerException- if key is null or algorithm is null or empty.IllegalArgumentException- if key is empty, or too short, i.e. key.length-offset<len.- See Also:
-
getPBE
PBEKeySpec object- Parameters:
password- the password- Returns:
- PBEKeySpec object
- See Also:
-
getPBE
public static PBEKeySpec getPBE(char[] password, byte[] salt, int iterationCount, int keyLength) throws NullPointerException, IllegalArgumentException PBEKeySpec object- Parameters:
password- the passwordsalt- the saltiterationCount- the iteration countkeyLength- the to-be-derived key length- Returns:
- PBEKeySpec object
- Throws:
NullPointerException- if salt is null.IllegalArgumentException- if salt is empty, i.e. 0-length, iterationCount or keyLength is not positive.- See Also:
-
getPKCS8
PKCS8EncodedKeySpec object- Parameters:
key- the key, which is assumed to be encoded according to the PKCS #8 standard. The contents of the array are copied to protect against subsequent modification.- Returns:
- PKCS8EncodedKeySpec object
- Throws:
NullPointerException- if key is null.- See Also:
-
getPKCS8
public static PKCS8EncodedKeySpec getPKCS8(byte[] key, String algorithm) throws NullPointerException, IllegalArgumentException PKCS8EncodedKeySpec object- Parameters:
key- the key, which is assumed to be encoded according to the PKCS #8 standard. The contents of the array are copied to protect against subsequent modification.algorithm- the algorithm name of the encoded private key.- Returns:
- PKCS8EncodedKeySpec object
- Throws:
NullPointerException- if key is nullIllegalArgumentException- if algorithm is the empty string- See Also:
-
getX509
X509EncodedKeySpec object- Parameters:
key- the key, which is assumed to be encoded according to the X.509 standard. The contents of the array are copied to protect against subsequent modification.- Returns:
- X509EncodedKeySpec object
- Throws:
NullPointerException- if key is null- See Also:
-
getX509
public static X509EncodedKeySpec getX509(byte[] key, String algorithm) throws NullPointerException, IllegalArgumentException X509EncodedKeySpec object- Parameters:
key- the key, which is assumed to be encoded according to the X.509 standard. The contents of the array are copied to protect against subsequent modification.algorithm- the algorithm name of the encoded public key.- Returns:
- X509EncodedKeySpec object
- Throws:
NullPointerException- if key is nullIllegalArgumentException- if algorithm is the empty string- See Also:
-
genPublicKey
public static PublicKey genPublicKey(KeyFactory keyFactory, X509EncodedKeySpec keySpec) throws InvalidKeySpecException Convert X509 to public key- Parameters:
keyFactory- KeyFactory objectkeySpec- X509 object- Returns:
- public key object
- Throws:
InvalidKeySpecException- if the given key specification is inappropriate for this key factory to produce a public key.
-
genPrivateKey
public static PrivateKey genPrivateKey(KeyFactory keyFactory, PKCS8EncodedKeySpec keySpec) throws InvalidKeySpecException Convert PKC8 to private key- Parameters:
keyFactory- KeyFactory objectkeySpec- PKC8 object- Returns:
- private key object
- Throws:
InvalidKeySpecException- if the given key specification is inappropriate for this key factory to produce a public key.
-
getXECPub
Construct a public key spec using the supplied parameters and u coordinate.- Parameters:
paramSpec- the algorithm parametersu- the u-coordinate of the point- Returns:
- XECPublicKeySpec object
-