|
2 | 2 | * Ant Group
|
3 | 3 | * Copyright (c) 2004-2024 All Rights Reserved.
|
4 | 4 | */
|
5 |
| -package com.alipay.global.api.request.ams.risk.tee.encryptstrategy; |
| 5 | +package com.alipay.global.api.request.ams.risk.tee.encryptutil; |
6 | 6 |
|
7 | 7 | import com.alipay.global.api.model.ams.UserName;
|
8 | 8 | import com.alipay.global.api.model.risk.Order;
|
|
13 | 13 | import com.alipay.global.api.request.ams.risk.tee.enums.EncryptKeyEnum;
|
14 | 14 | import com.alipay.global.api.request.ams.risk.tee.enums.ErrorCodeEnum;
|
15 | 15 | import com.alipay.global.api.request.ams.risk.tee.exception.CryptoException;
|
16 |
| - |
17 | 16 | import javax.xml.bind.DatatypeConverter;
|
18 | 17 | import java.nio.charset.Charset;
|
19 | 18 | import java.util.List;
|
|
22 | 21 | * request encrypt strategy for risk decide API
|
23 | 22 | * risk decide API 的请求加密策略
|
24 | 23 | */
|
25 |
| -public class RiskDecideEncryptStrategy implements EncryptStrategy { |
| 24 | +public class RiskDecideEncryptUtil { |
26 | 25 |
|
27 |
| - Charset utf8Charset = Charset.forName("UTF-8"); |
| 26 | + private static Charset utf8Charset = Charset.forName("UTF-8"); |
28 | 27 |
|
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) { |
31 | 29 | if (request == null || encryptKeyList == null) {
|
32 | 30 | return;
|
33 | 31 | }
|
34 | 32 | 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"); |
36 | 34 | }
|
37 | 35 | RiskDecideRequest riskDecideRequest = (RiskDecideRequest) request;
|
38 | 36 | 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); |
45 | 38 | }
|
46 | 39 |
|
47 | 40 | /**
|
48 | 41 | * do encrypt by encryptKeyList
|
49 | 42 | * 根据 encryptKeyList 进行加密
|
50 |
| - * |
51 |
| - * @param data_key symmetric key |
52 |
| - * @param request plaintext RiskDecideRequest |
| 43 | + * @param data_key symmetric key |
| 44 | + * @param request plaintext RiskDecideRequest |
53 | 45 | * @param encryptKeyList list of encrypt keys
|
54 |
| - * @param crypto AESCrypto instance |
| 46 | + * @param crypto AESCrypto instance |
55 | 47 | */
|
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, |
57 | 49 | AESCrypto crypto) {
|
58 | 50 | List<Order> orders = request.getOrders();
|
59 | 51 | List<PaymentDetail> paymentDetails = request.getPaymentDetails();
|
@@ -146,12 +138,11 @@ private void doEncrypt(byte[] data_key, RiskDecideRequest request, List<EncryptK
|
146 | 138 | /**
|
147 | 139 | * encrypt username
|
148 | 140 | * 加密 username
|
149 |
| - * |
150 | 141 | * @param data_key symmetric key
|
151 | 142 | * @param userName user name
|
152 |
| - * @param crypto AESCrypto instance |
| 143 | + * @param crypto AESCrypto instance |
153 | 144 | */
|
154 |
| - private void encryptName(byte[] data_key, UserName userName, AESCrypto crypto) { |
| 145 | + private static void encryptName(byte[] data_key, UserName userName, AESCrypto crypto) { |
155 | 146 | if (userName == null) {
|
156 | 147 | return;
|
157 | 148 | }
|
|
0 commit comments