uft-8 改为 StandardCharsets.UTF_8

This commit is contained in:
2023-12-15 16:06:21 +08:00
parent ff9f4faecb
commit 517320e714
11 changed files with 33 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -35,7 +36,7 @@ public class AesUtil {
cipher.init(Cipher.DECRYPT_MODE, key, spec);
cipher.updateAAD(associatedData);
return new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)), "utf-8");
return new String(cipher.doFinal(Base64.getDecoder().decode(ciphertext)), StandardCharsets.UTF_8);
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new IllegalStateException(e);
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {

View File

@@ -6,6 +6,7 @@ import com.jsowell.wxpay.common.WeChatPayParameter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.InvalidKeyException;
@@ -36,7 +37,7 @@ public class WechatPayUtils {
*/
public static PrivateKey getPrivateKey(String filename) throws IOException {
// System.out.println("filename:" + filename);
String content = new String(Files.readAllBytes(Paths.get(filename)), "utf-8");
String content = new String(Files.readAllBytes(Paths.get(filename)), StandardCharsets.UTF_8);
try {
String privateKey = content.replace("-----BEGIN PRIVATE KEY-----", "")
.replace("-----END PRIVATE KEY-----", "")
@@ -64,7 +65,7 @@ public class WechatPayUtils {
String nonceStr = getNonceStr();
long timestamp = System.currentTimeMillis() / 1000;
String message = buildMessage(method, url, timestamp, nonceStr, body);
String signature = sign(message.getBytes("utf-8"));
String signature = sign(message.getBytes(StandardCharsets.UTF_8));
return "WECHATPAY2-SHA256-RSA2048 " + "mchid=\"" + WeChatPayParameter.mchId + "\","
+ "nonce_str=\"" + nonceStr + "\","
@@ -86,7 +87,7 @@ public class WechatPayUtils {
String nonceStr = getNonceStr();
long timestamp = System.currentTimeMillis() / 1000;
String message = buildMessage(method, url, timestamp, nonceStr, body);
String signature = sign(message.getBytes("utf-8"));
String signature = sign(message.getBytes(StandardCharsets.UTF_8));
Map<String, Object> map = new HashMap<>();
map.put("timeStamp", String.valueOf(timestamp));
@@ -170,7 +171,7 @@ public class WechatPayUtils {
//证书内容转成证书对象
CertificateFactory cf = CertificateFactory.getInstance("X509");
X509Certificate x509Cert = (X509Certificate) cf.generateCertificate(
new ByteArrayInputStream(certStr.getBytes("utf-8"))
new ByteArrayInputStream(certStr.getBytes(StandardCharsets.UTF_8))
);
String serial_no = data.get(i).get("serial_no").toString().replaceAll("\"", "");
certificateMap.put(serial_no, x509Cert);
@@ -222,7 +223,7 @@ public class WechatPayUtils {
//签名使用字段appId、timeStamp、nonceStr、package计算得出的签名值
String message = buildMessageTwo(appId, timestamp, nonceStr, packagestr);
//获取对应的签名
String signature = sign(message.getBytes("utf-8"));
String signature = sign(message.getBytes(StandardCharsets.UTF_8));
// 组装返回
HashMap<String, Object> map = new HashMap<>();
map.put("timeStamp", String.valueOf(timestamp));