浏览代码

小程序后台代码提交,登录, 修改加密方法

tags/B.2.6.1_20240104_release^2
yk 1年前
父节点
当前提交
d0b8490ae9
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. +5
    -2
      xueyi-common/xueyi-common-core/src/main/java/com/xueyi/common/core/utils/core/CryptoUtil.java

+ 5
- 2
xueyi-common/xueyi-common-core/src/main/java/com/xueyi/common/core/utils/core/CryptoUtil.java 查看文件

@@ -3,6 +3,7 @@ package com.xueyi.common.core.utils.core;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import java.util.Base64;

/**
* @author yk
@@ -25,15 +26,17 @@ public class CryptoUtil {
byte[] ciphertext = cipher.doFinal(data.getBytes());

// 输出密文
return new String(ciphertext);
return Base64.getEncoder().encodeToString(ciphertext);
}


public static String decrypt(String encryptedData) throws Exception {
byte[] encryptedDataBytes = Base64.getDecoder().decode(encryptedData);
Key k = new SecretKeySpec(DEFAULT_KEY.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, k);
byte[] decryptedBytes = cipher.doFinal(encryptedData.getBytes());
byte[] decryptedBytes = cipher.doFinal(encryptedDataBytes);
//base64加密
return new String(decryptedBytes);
}
}

正在加载...
取消
保存