public class SecurityUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
ALGORITHM
选择加密算法
JDK6支持以下任意一种算法
PBEWITHMD5ANDDES
PBEWITHMD5ANDTRIPLEDES
PBEWITHSHAANDDESEDE
PBEWITHSHA1ANDRC2_40
PBKDF2WITHHMACSHA1
|
static String |
SALT
密钥
|
| 构造器和说明 |
|---|
SecurityUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
bytesToHexString(byte[] src)
Description:
将字节数组转换为十六进制字符串 |
static String |
decrypt(String decryptPassword,
String encryptedVal)
Description:
解密密文字符串 |
static String |
decrypt(String decryptPassword,
String encryptedVal,
byte[] salt)
Description:
解密密文字符串 |
static String |
encrypt(String encryPassword,
String strVal)
Description:
加密明文字符串 |
static String |
encrypt(String encryPassword,
String strVal,
byte[] salt)
Description:
加密明文字符串 |
static byte[] |
getSalt()
Description:
获取加密算法中使用的盐值,解密中使用的盐值必须与加密中使用的相同才能完成操作. |
static byte[] |
getStaticSalt()
Description:
产出盐 |
static byte[] |
hexStringToBytes(String hexString)
Description:
将十六进制字符串转换为字节数组 |
static void |
main(String[] args) |
public static final String ALGORITHM
public static byte[] getSalt()
throws Exception
Exceptionpublic static byte[] getStaticSalt()
public static String encrypt(String encryPassword, String strVal, byte[] salt)
encryPassword - 生成密钥时所使用的密码(加密的密码,这里用用户名来代替)strVal - 待加密的明文字符串salt - 盐值public static String encrypt(String encryPassword, String strVal)
encryPassword - 生成密钥时所使用的密码(加密的密码,这里用用户名来代替)strVal - 待加密的明文字符串public static String decrypt(String decryptPassword, String encryptedVal, byte[] salt)
decryptPassword - 生成密钥时所使用的密码(解密的密码)encryptedVal - 待解密的明文字符串salt - 盐值(如需解密,该参数需要与加密时使用的一致)public static String decrypt(String decryptPassword, String encryptedVal)
decryptPassword - 生成密钥时所使用的密码(解密的密码)encryptedVal - 待解密的明文字符串public static String bytesToHexString(byte[] src)
src - 字节数组public static byte[] hexStringToBytes(String hexString)
hexString - 十六进制字符串public static void main(String[] args)
Copyright © 2016. All rights reserved.