|
|
@@ -531,6 +531,33 @@ public class ToolsUtils {
|
|
|
return new String(decryptedByteArray, StandardCharsets.UTF_8);
|
|
|
}
|
|
|
|
|
|
+ public static String encryptDesNew(String source, String pass) throws Exception {
|
|
|
+ byte[] rgbKey = pass.getBytes("UTF-8");
|
|
|
+ byte[] rgbIV = pass.getBytes("UTF-8");
|
|
|
+ Cipher cipher = Cipher.getInstance("DES");
|
|
|
+ SecretKeySpec keySpec = new SecretKeySpec(rgbKey, "DES");
|
|
|
+ IvParameterSpec ivSpec = new IvParameterSpec(rgbIV); cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
|
|
|
+ byte[] inputByteArray = source.getBytes("UTF-8");
|
|
|
+ byte[] encryptedByteArray = cipher.doFinal(inputByteArray);
|
|
|
+ return Base64.getEncoder().encodeToString(encryptedByteArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
|
|
|
+ Des解密
|
|
|
+ @param source 源字符串
|
|
|
+ @param pass 密钥,长度必须8位
|
|
|
+ @return 解密后的字符串 */
|
|
|
+ public static String decryptDesNew(String source, String pass) throws Exception {
|
|
|
+ byte[] rgbKey = pass.getBytes("UTF-8");
|
|
|
+ byte[] rgbIV = pass.getBytes("UTF-8");
|
|
|
+ Cipher cipher = Cipher.getInstance("DES");
|
|
|
+ SecretKeySpec keySpec = new SecretKeySpec(rgbKey, "DES");
|
|
|
+ IvParameterSpec ivSpec = new IvParameterSpec(rgbIV);
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
|
|
+ byte[] inputByteArray = Base64.getDecoder().decode(source);
|
|
|
+ byte[] decryptedByteArray = cipher.doFinal(inputByteArray);
|
|
|
+ return new String(decryptedByteArray, "UTF-8");
|
|
|
+ }
|
|
|
|
|
|
}
|