Skip to content

Commit 2447b86

Browse files
authored
Merge pull request #41 from alipay/risk_tee
Risk tee
2 parents 57fe2a1 + e866a1a commit 2447b86

File tree

5 files changed

+21
-70
lines changed

5 files changed

+21
-70
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.38</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: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import com.alipay.global.api.request.ams.risk.RiskReportRequest;
1717
import com.alipay.global.api.request.ams.risk.SendPaymentResultRequest;
1818
import com.alipay.global.api.request.ams.risk.SendRefundResultRequest;
19-
import com.alipay.global.api.request.ams.risk.tee.encryptstrategy.RiskDecideEncryptStrategy;
20-
import com.alipay.global.api.request.ams.risk.tee.enums.EncryptKeyEnum;
2119
import com.alipay.global.api.request.ams.risk.tee.exception.CryptoException;
2220
import com.alipay.global.api.response.ams.risk.RiskDecideResponse;
2321
import com.alipay.global.api.response.ams.risk.RiskReportResponse;
2422
import com.alipay.global.api.response.ams.risk.SendPaymentResultResponse;
2523
import com.alipay.global.api.response.ams.risk.SendRefundResultResponse;
24+
import com.alipay.global.api.request.ams.risk.tee.encryptutil.RiskDecideEncryptUtil;
25+
import com.alipay.global.api.request.ams.risk.tee.enums.EncryptKeyEnum;
2626

2727
import java.util.Arrays;
2828
import java.util.Collections;
@@ -95,8 +95,8 @@ public static RiskDecideResponse postAuthDecide() {
9595
return response;
9696
}
9797

98-
public static void encryptRequest(RiskDecideRequest request) throws CryptoException {
99-
// 2.1. build encryptList
98+
private static void encryptRequest(RiskDecideRequest request) throws CryptoException {
99+
// 2.1. please confirm selected encryptKey whit Ant Group, build encryptList
100100
List<EncryptKeyEnum> encryptList = Arrays.asList(
101101
EncryptKeyEnum.BUYER_EMAIL,
102102
EncryptKeyEnum.BUYER_PHONE_NO,
@@ -108,9 +108,8 @@ public static void encryptRequest(RiskDecideRequest request) throws CryptoExcept
108108
EncryptKeyEnum.SHIP_TO_EMAIL,
109109
EncryptKeyEnum.SHIPPING_PHONE_NO
110110
);
111-
// 2.2. encrypt request by using RiskDecideEncryptStrategy
112-
RiskDecideEncryptStrategy strategy = new RiskDecideEncryptStrategy();
113-
strategy.encrypt(DATA_KEY, request, encryptList);
111+
// 2.2. encrypt request by using RiskDecideEncryptUtil
112+
RiskDecideEncryptUtil.encrypt(DATA_KEY, request, encryptList);
114113
}
115114

116115
public static SendPaymentResultResponse sendPaymentResult() {

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

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 12 additions & 21 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;
@@ -13,7 +13,6 @@
1313
import com.alipay.global.api.request.ams.risk.tee.enums.EncryptKeyEnum;
1414
import com.alipay.global.api.request.ams.risk.tee.enums.ErrorCodeEnum;
1515
import com.alipay.global.api.request.ams.risk.tee.exception.CryptoException;
16-
1716
import javax.xml.bind.DatatypeConverter;
1817
import java.nio.charset.Charset;
1918
import java.util.List;
@@ -22,38 +21,31 @@
2221
* request encrypt strategy for risk decide API
2322
* risk decide API 的请求加密策略
2423
*/
25-
public class RiskDecideEncryptStrategy implements EncryptStrategy {
24+
public class RiskDecideEncryptUtil {
2625

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

29-
@Override
30-
public void encrypt(byte[] data_key, AlipayRequest<?> request, List<EncryptKeyEnum> encryptKeyList) {
28+
public static void encrypt(String dataKeyBase64, AlipayRequest<?> request, List<EncryptKeyEnum> encryptKeyList) {
3129
if (request == null || encryptKeyList == null) {
3230
return;
3331
}
3432
if (!(request instanceof RiskDecideRequest)) {
35-
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");
3634
}
3735
RiskDecideRequest riskDecideRequest = (RiskDecideRequest) request;
3836
AESCrypto crypto = AESCrypto.getInstance();
39-
doEncrypt(data_key, riskDecideRequest, encryptKeyList, crypto);
40-
}
41-
42-
@Override
43-
public void encrypt(String dataKeyBase64, AlipayRequest<?> request, List<EncryptKeyEnum> encryptKeyList) {
44-
encrypt(DatatypeConverter.parseBase64Binary(dataKeyBase64), request, encryptKeyList);
37+
doEncrypt(DatatypeConverter.parseBase64Binary(dataKeyBase64), riskDecideRequest, encryptKeyList, crypto);
4538
}
4639

4740
/**
4841
* do encrypt by encryptKeyList
4942
* 根据 encryptKeyList 进行加密
50-
*
51-
* @param data_key symmetric key
52-
* @param request plaintext RiskDecideRequest
43+
* @param data_key symmetric key
44+
* @param request plaintext RiskDecideRequest
5345
* @param encryptKeyList list of encrypt keys
54-
* @param crypto AESCrypto instance
46+
* @param crypto AESCrypto instance
5547
*/
56-
private void doEncrypt(byte[] data_key, RiskDecideRequest request, List<EncryptKeyEnum> encryptKeyList,
48+
private static void doEncrypt(byte[] data_key, RiskDecideRequest request, List<EncryptKeyEnum> encryptKeyList,
5749
AESCrypto crypto) {
5850
List<Order> orders = request.getOrders();
5951
List<PaymentDetail> paymentDetails = request.getPaymentDetails();
@@ -146,12 +138,11 @@ private void doEncrypt(byte[] data_key, RiskDecideRequest request, List<EncryptK
146138
/**
147139
* encrypt username
148140
* 加密 username
149-
*
150141
* @param data_key symmetric key
151142
* @param userName user name
152-
* @param crypto AESCrypto instance
143+
* @param crypto AESCrypto instance
153144
*/
154-
private void encryptName(byte[] data_key, UserName userName, AESCrypto crypto) {
145+
private static void encryptName(byte[] data_key, UserName userName, AESCrypto crypto) {
155146
if (userName == null) {
156147
return;
157148
}

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

Lines changed: 2 additions & 4 deletions
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;
@@ -38,7 +38,5 @@ public String getCode() {
3838
return code;
3939
}
4040

41-
public String getDescription() {
42-
return description;
43-
}
41+
public String getDescription() { return description; }
4442
}

0 commit comments

Comments
 (0)