新增AES加密方式
This commit is contained in:
parent
ae06a9791f
commit
3ddf96bd4c
@ -77,7 +77,11 @@ public class WechatMiniAppAuthServiceImpl implements IWechatMiniAppAuthService {
|
||||
LOG.debug("绑定用户 | 登录");
|
||||
String wechatSignInfo = Base64.encodeBase64String(AesUtil.aesCommonEncoder("WECHAT_SIGN_INFO", new StringBuilder(wechatMiniAppUserInfo.getOpenid()).append("_WenG_").append(wechatMiniAppProperties.getAppKey()).toString()).getBytes("UTF-8"));
|
||||
String token = getAppToken(wechatSignInfo);
|
||||
if (token.endsWith("_0") || token.endsWith("_1")) {
|
||||
WechatMiniAppManager.getInstance().addUser(token.substring(0, token.length() - 2), wechatMiniAppUserInfo);
|
||||
} else {
|
||||
WechatMiniAppManager.getInstance().addUser(token, wechatMiniAppUserInfo);
|
||||
}
|
||||
return new SuccessResultData(token);
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,13 @@
|
||||
package com.cm.common.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.codec.binary.StringUtils;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.*;
|
||||
|
||||
public class AesUtil {
|
||||
|
||||
@ -110,6 +108,9 @@ public class AesUtil {
|
||||
byte[] enCodeFormat = key.getBytes();
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes);
|
||||
if (StringUtils.equals(paddingType, PKCS_7)) {
|
||||
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
||||
}
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/" + paddingType);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
|
||||
return cipher.doFinal(byteContent);
|
||||
@ -143,7 +144,11 @@ public class AesUtil {
|
||||
public static byte[] aesCommonDecoderDetail(byte[] keyBytes, byte[] encryptedBytes, byte[] ivBytes, String paddingType) throws Exception {
|
||||
SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES");
|
||||
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes);
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/" + paddingType);
|
||||
Cipher cipher;
|
||||
if (StringUtils.equals(paddingType, PKCS_7)) {
|
||||
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
|
||||
}
|
||||
cipher = Cipher.getInstance("AES/CBC/" + paddingType);
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec);
|
||||
return cipher.doFinal(encryptedBytes);
|
||||
}
|
||||
|
8
pom.xml
8
pom.xml
@ -78,6 +78,7 @@
|
||||
<jna-platform.version>5.5.0</jna-platform.version>
|
||||
<spring-security-jwt.version>1.0.9.RELEASE</spring-security-jwt.version>
|
||||
<netty.version>4.1.50.Final</netty.version>
|
||||
<bouncycastle.version>1.46</bouncycastle.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖管理 -->
|
||||
@ -431,6 +432,13 @@
|
||||
<version>${netty.version}</version>
|
||||
</dependency>
|
||||
<!-- netty end -->
|
||||
<!-- bouncycastle start -->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.56</version>
|
||||
</dependency>
|
||||
<!-- bouncycastle end -->
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user