Browse Source

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

tags/B.2.6.1_20240104_release^2
yk 1 year ago
parent
commit
9f76ec8b12
2 changed files with 41 additions and 1 deletions
  1. +39
    -0
      xueyi-common/xueyi-common-core/src/main/java/com/xueyi/common/core/utils/core/CryptoUtil.java
  2. +2
    -1
      xueyi-modules/xueyi-system/src/main/java/com/xueyi/system/wechat/controller/WeChatController.java

+ 39
- 0
xueyi-common/xueyi-common-core/src/main/java/com/xueyi/common/core/utils/core/CryptoUtil.java View File

@@ -0,0 +1,39 @@
package com.xueyi.common.core.utils.core;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;

/**
* @author yk
* @description
* @date 2024-01-03 18:48
*/
public class CryptoUtil {
public static final String DEFAULT_KEY = "8237uw823wuyeuwiyeehbsuuwgwvsyyeuii";

public static String encrypt(String data) throws Exception{
Key k = new SecretKeySpec(DEFAULT_KEY.getBytes(), "AES");

// 创建 Cipher 对象
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");

// 初始化 Cipher 对象
cipher.init(Cipher.ENCRYPT_MODE, k);

// 加密数据
byte[] ciphertext = cipher.doFinal(data.getBytes());

// 输出密文
return new String(ciphertext);
}


public static String decrypt(String encryptedData) throws Exception {
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());
return new String(decryptedBytes);
}
}

+ 2
- 1
xueyi-modules/xueyi-system/src/main/java/com/xueyi/system/wechat/controller/WeChatController.java View File

@@ -4,6 +4,7 @@ import com.baomidou.dynamic.datasource.toolkit.CryptoUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xueyi.common.core.constant.basic.SecurityConstants;
import com.xueyi.common.core.utils.core.CryptoUtil;
import com.xueyi.common.core.utils.core.ObjectUtil;
import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.common.core.web.result.R;
@@ -71,7 +72,7 @@ public class WeChatController {
R<SysEnterpriseStaff> staff = tenantService.existStaff(weChatUserInfo.getOpenid(), SecurityConstants.INNER);
Map<String, Object> map = new HashMap<>();
try {
map.put("wechat_auth", CryptoUtils.encrypt(weChatUserInfo.toString()));
map.put("wechat_auth", CryptoUtil.encrypt(weChatUserInfo.toString()));
if (staff.getData() != null) {
R<LoginUser> loginInfoResult = remoteLoginService.getLoginInfoInnerByPhone(staff.getData().getPhone(), SecurityConstants.INNER);
map.putAll(tokenService.createToken(loginInfoResult.getData()));


Loading…
Cancel
Save