Client本地加解密,comon
加了缓存加快速度
盐值是UUID
public byte[][] generateKeyGroup(Map<String, String> genMetaData, boolean isKeyEncrypted) throws KeyCenterAlgorithmException {
UUID uuid = UUID.randomUUID();
String randomSalt = uuid.toString().trim().replaceAll("-", "");
byte[][] keyBytes = new byte[1][];
if (isKeyEncrypted) {
keyBytes[0] = this.encryptKeyContent(randomSalt.getBytes(), false);
} else {
keyBytes[0] = randomSalt.getBytes();
}
return keyBytes;
}
SecurityUtil
/**
* 生成盐值
*/
public static String generateSalt(){
SecureRandom secureRandom = new SecureRandom();
//与SHA256对应,盐的长度是32个字节的随机数据。
byte[] bytes = new byte[32];
secureRandom.nextBytes(bytes);
return new BASE64Encoder().encode(bytes);
}