Skip to content

Commit ab67947

Browse files
committed
update: TEE encrypt util upgrade
1 parent ff7712f commit ab67947

File tree

5 files changed

+15
-57
lines changed

5 files changed

+15
-57
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.alipay.global.sdk</groupId>
55
<artifactId>global-open-sdk-java</artifactId>
66
<packaging>jar</packaging>
7-
<version>2.0.30</version>
7+
<version>2.0.39</version>
88
<name>global-open-sdk-java</name>
99
<url>https://github.com/alipay/global-open-sdk-java</url>
1010
<description>

src/main/java/com/alipay/global/api/example/RiskDecideTeeDemoCode.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import com.alipay.global.api.response.ams.risk.RiskReportResponse;
3434
import com.alipay.global.api.response.ams.risk.SendPaymentResultResponse;
3535
import com.alipay.global.api.response.ams.risk.SendRefundResultResponse;
36-
import com.alipay.global.api.request.ams.risk.tee.encryptstrategy.RiskDecideEncryptStrategy;
36+
import com.alipay.global.api.request.ams.risk.tee.encryptutil.RiskDecideEncryptUtil;
3737
import com.alipay.global.api.request.ams.risk.tee.enums.EncryptKeyEnum;
3838

3939
import java.util.Arrays;
@@ -106,8 +106,8 @@ public static RiskDecideResponse postAuthDecide() {
106106
return response;
107107
}
108108

109-
public static void encryptRequest(RiskDecideRequest request) throws CryptoException {
110-
// 2.1. build encryptList
109+
private static void encryptRequest(RiskDecideRequest request) throws CryptoException {
110+
// 2.1. please confirm selected encryptKey whit Ant Group, build encryptList
111111
List<EncryptKeyEnum> encryptList = Arrays.asList(
112112
EncryptKeyEnum.BUYER_EMAIL,
113113
EncryptKeyEnum.BUYER_PHONE_NO,
@@ -119,9 +119,8 @@ public static void encryptRequest(RiskDecideRequest request) throws CryptoExcept
119119
EncryptKeyEnum.SHIP_TO_EMAIL,
120120
EncryptKeyEnum.SHIPPING_PHONE_NO
121121
);
122-
// 2.2. encrypt request by using RiskDecideEncryptStrategy
123-
RiskDecideEncryptStrategy strategy = new RiskDecideEncryptStrategy();
124-
strategy.encrypt(DATA_KEY, request, encryptList);
122+
// 2.2. encrypt request by using RiskDecideEncryptUtil
123+
RiskDecideEncryptUtil.encrypt(DATA_KEY, request, encryptList);
125124
}
126125

127126
public static SendPaymentResultResponse sendPaymentResult() {

src/main/java/com/alipay/global/api/request/ams/risk/tee/encryptstrategy/EncryptStrategy.java

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Ant Group
33
* Copyright (c) 2004-2024 All Rights Reserved.
44
*/
5-
package com.alipay.global.api.request.ams.risk.tee.encryptstrategy;
5+
package com.alipay.global.api.request.ams.risk.tee.encryptutil;
66

77
import com.alipay.global.api.model.ams.UserName;
88
import com.alipay.global.api.model.risk.Order;
@@ -21,26 +21,20 @@
2121
* request encrypt strategy for risk decide API
2222
* risk decide API 的请求加密策略
2323
*/
24-
public class RiskDecideEncryptStrategy implements EncryptStrategy{
24+
public class RiskDecideEncryptUtil {
2525

26-
Charset utf8Charset = Charset.forName("UTF-8");
26+
private static Charset utf8Charset = Charset.forName("UTF-8");
2727

28-
@Override
29-
public void encrypt(byte[] data_key, AlipayRequest<?> request, List<EncryptKeyEnum> encryptKeyList) {
28+
public static void encrypt(String dataKeyBase64, AlipayRequest<?> request, List<EncryptKeyEnum> encryptKeyList) {
3029
if (request == null || encryptKeyList == null) {
3130
return;
3231
}
3332
if (!(request instanceof RiskDecideRequest)) {
34-
throw new CryptoException(ErrorCodeEnum.MISMATCH_ENCRYPT_STRATEGY, "Request is not instance of RiskDecideRequest");
33+
throw new CryptoException(ErrorCodeEnum.MISMATCH_ENCRYPT_UTIL, "Request is not instance of RiskDecideRequest");
3534
}
3635
RiskDecideRequest riskDecideRequest = (RiskDecideRequest) request;
3736
AESCrypto crypto = AESCrypto.getInstance();
38-
doEncrypt(data_key, riskDecideRequest, encryptKeyList, crypto);
39-
}
40-
41-
@Override
42-
public void encrypt(String dataKeyBase64, AlipayRequest<?> request, List<EncryptKeyEnum> encryptKeyList) {
43-
encrypt(DatatypeConverter.parseBase64Binary(dataKeyBase64), request, encryptKeyList);
37+
doEncrypt(DatatypeConverter.parseBase64Binary(dataKeyBase64), riskDecideRequest, encryptKeyList, crypto);
4438
}
4539

4640
/**
@@ -51,7 +45,7 @@ public void encrypt(String dataKeyBase64, AlipayRequest<?> request, List<Encrypt
5145
* @param encryptKeyList list of encrypt keys
5246
* @param crypto AESCrypto instance
5347
*/
54-
private void doEncrypt(byte[] data_key, RiskDecideRequest request, List<EncryptKeyEnum> encryptKeyList,
48+
private static void doEncrypt(byte[] data_key, RiskDecideRequest request, List<EncryptKeyEnum> encryptKeyList,
5549
AESCrypto crypto) {
5650
List<Order> orders = request.getOrders();
5751
List<PaymentDetail> paymentDetails = request.getPaymentDetails();
@@ -148,7 +142,7 @@ private void doEncrypt(byte[] data_key, RiskDecideRequest request, List<EncryptK
148142
* @param userName user name
149143
* @param crypto AESCrypto instance
150144
*/
151-
private void encryptName(byte[] data_key, UserName userName, AESCrypto crypto) {
145+
private static void encryptName(byte[] data_key, UserName userName, AESCrypto crypto) {
152146
if (userName == null) {
153147
return;
154148
}

src/main/java/com/alipay/global/api/request/ams/risk/tee/enums/ErrorCodeEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum ErrorCodeEnum {
1212
PARAM_ILLEGAL("PARAM_ILLEGAL", "param illegal"),
1313
ENCRYPT_ERROR("ENCRYPT_ERROR", "encrypt error"),
1414
UNKNOWN_ENCRYPT_KEY("UNKNOWN_ENCRYPT_KEY", "unknown encrypt key"),
15-
MISMATCH_ENCRYPT_STRATEGY("MISMATCH_ENCRYPT_STRATEGY","mismatch encrypt strategy"),
15+
MISMATCH_ENCRYPT_UTIL("MISMATCH_ENCRYPT_UTIL","mismatch encrypt util"),
1616
;
1717

1818
private final String code;

0 commit comments

Comments
 (0)