Package tech.mgl.core.utils.security
Class MGL_Rfc2898DeriveBytes
java.lang.Object
tech.mgl.core.utils.security.MGL_Rfc2898DeriveBytes
salt + md5这样的时候用的 但是目前还不采用 因为有人研究过此方法也并不安全
ClassName: Rfc2898DeriveBytes
- Author:
- hotpot ...
-
Constructor Summary
ConstructorsConstructorDescriptionMGL_Rfc2898DeriveBytes(byte[] password, byte[] salt, int iterations) Creates new instance.MGL_Rfc2898DeriveBytes(String password, byte[] salt, int iterations) Creates new instance.MGL_Rfc2898DeriveBytes(String password, int saltSize) Creates new instance.MGL_Rfc2898DeriveBytes(String password, int saltSize, int iterations) Creates new instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateSalt(int size) Generate random Saltbyte[]getBytes(int cb) Returns a pseudo-random key from a data, salt and iteration count.byte[]getSalt()static byte[]randomSalt(int size)
-
Constructor Details
-
MGL_Rfc2898DeriveBytes
public MGL_Rfc2898DeriveBytes(byte[] password, byte[] salt, int iterations) throws NoSuchAlgorithmException, InvalidKeyException Creates new instance.- Parameters:
password- The password used to derive the key.salt- The key salt used to derive the key.iterations- The number of iterations for the operation.- Throws:
NoSuchAlgorithmException- HmacSHA1 algorithm cannot be found.InvalidKeyException- Salt must be 8 bytes or more. -or- Password cannot be null.
-
MGL_Rfc2898DeriveBytes
public MGL_Rfc2898DeriveBytes(String password, int saltSize, int iterations) throws NoSuchAlgorithmException, InvalidKeyException Creates new instance.- Parameters:
password- The password used to derive the key.saltSize- The key salt used to derive the key.iterations- The number of iterations for the operation.- Throws:
NoSuchAlgorithmException- HmacSHA1 algorithm cannot be found.InvalidKeyException- Salt must be 8 bytes or more. -or- Password cannot be null.
-
MGL_Rfc2898DeriveBytes
public MGL_Rfc2898DeriveBytes(String password, int saltSize) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException Creates new instance.- Parameters:
password- The password used to derive the key.saltSize- The key salt used to derive the key.- Throws:
NoSuchAlgorithmException- HmacSHA1 algorithm cannot be found.InvalidKeyException- Salt must be 8 bytes or more. -or- Password cannot be null.UnsupportedEncodingException
-
MGL_Rfc2898DeriveBytes
public MGL_Rfc2898DeriveBytes(String password, byte[] salt, int iterations) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException Creates new instance.- Parameters:
password- The password used to derive the key.salt- The key salt used to derive the key.iterations- The number of iterations for the operation.- Throws:
NoSuchAlgorithmException- HmacSHA1 algorithm cannot be found.InvalidKeyException- Salt must be 8 bytes or more. -or- Password cannot be null.UnsupportedEncodingException- UTF-8 encoding is not supported.
-
-
Method Details
-
getSalt
public byte[] getSalt() -
getSaltAsString
-
getBytes
public byte[] getBytes(int cb) Returns a pseudo-random key from a data, salt and iteration count.- Parameters:
cb- Number of bytes to return.- Returns:
- Byte array.
-
randomSalt
public static byte[] randomSalt(int size) -
generateSalt
Generate random Salt- Parameters:
size-- Returns:
-