This is an automated email from the ASF dual-hosted git repository.

funky-eyes pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new d7ad0f5b70 bugfix: use UTF-8 for ConfigTools encryption (#8170)
d7ad0f5b70 is described below

commit d7ad0f5b70f65bb3967c18ae015c61fca99637be
Author: pyshiweijia <[email protected]>
AuthorDate: Sat Jul 25 20:14:11 2026 +0800

    bugfix: use UTF-8 for ConfigTools encryption (#8170)
---
 changes/en-us/2.x.md                                                  | 2 ++
 changes/zh-cn/2.x.md                                                  | 2 ++
 common/src/main/java/org/apache/seata/common/util/ConfigTools.java    | 4 ++--
 .../src/test/java/org/apache/seata/common/util/ConfigToolsTest.java   | 4 ++--
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 0fba96469d..5c3afb7420 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -27,6 +27,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#8138](https://github.com/apache/incubator-seata/pull/8138)] fix TCC fence 
cleanup deleting in-progress/unexpired sibling branch records
 - [[#8145](https://github.com/apache/incubator-seata/pull/8145)] fix global 
lock batch acquire false-failure on Dameng(DM)
 - [[#8157](https://github.com/apache/incubator-seata/pull/8157)] fix Saga 
auto-configuration being skipped on Spring Boot 4.x because of a hard 
`DataSourceAutoConfiguration` class reference
+- [[#8170](https://github.com/apache/incubator-seata/pull/8170)] fix 
ConfigTools encryption corrupting non-ASCII content on non-UTF-8 platforms
 
 
 
@@ -60,6 +61,7 @@ Thanks to these contributors for their code commits. Please 
report an unintended
 - [lhozy](https://github.com/lhozy)
 - [Zhengcy05](https://github.com/Zhengcy05)
 - [neu-hsc](https://github.com/neu-hsc)
+- [pyshiweijia](https://github.com/pyshiweijia)
 
 
 
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index b04dd48651..b4f0545d11 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -27,6 +27,7 @@
 - [[#8138](https://github.com/apache/incubator-seata/pull/8138)] 修复 TCC fence 
清理时误删同一全局事务中仍在进行(TRIED)或未过期的分支记录的问题
 - [#8145](https://github.com/apache/incubator-seata/pull/8145) 
修复达梦(DM)数据库下全局锁批量获取被误判为失败的问题
 - [[#8157](https://github.com/apache/incubator-seata/pull/8157)] 修复 Spring 
Boot 4.x 下由于硬编码 `DataSourceAutoConfiguration` 类引用导致 Saga 自动配置被跳过的问题
+- [[#8170](https://github.com/apache/incubator-seata/pull/8170)] 修复 
ConfigTools 加密在非 UTF-8 默认字符集平台损坏非 ASCII 内容的问题
 
 
 ### optimize:
@@ -59,6 +60,7 @@
 - [lhozy](https://github.com/lhozy)
 - [Zhengcy05](https://github.com/Zhengcy05)
 - [neu-hsc](https://github.com/neu-hsc)
+- [pyshiweijia](https://github.com/pyshiweijia)
 
 
 
diff --git a/common/src/main/java/org/apache/seata/common/util/ConfigTools.java 
b/common/src/main/java/org/apache/seata/common/util/ConfigTools.java
index b566a4e6c2..8b68f3e2d3 100644
--- a/common/src/main/java/org/apache/seata/common/util/ConfigTools.java
+++ b/common/src/main/java/org/apache/seata/common/util/ConfigTools.java
@@ -111,7 +111,7 @@ public class ConfigTools {
         PublicKey publicKey = string2PublicKey(pubStr);
         Cipher cipher = Cipher.getInstance("RSA");
         cipher.init(Cipher.ENCRYPT_MODE, publicKey);
-        byte[] bytes = cipher.doFinal(content.getBytes());
+        byte[] bytes = 
cipher.doFinal(content.getBytes(StandardCharsets.UTF_8));
         return byte2Base64(bytes);
     }
 
@@ -143,7 +143,7 @@ public class ConfigTools {
         PrivateKey privateKey = string2PrivateKey(priStr);
         Cipher cipher = Cipher.getInstance("RSA");
         cipher.init(Cipher.ENCRYPT_MODE, privateKey);
-        byte[] bytes = cipher.doFinal(content.getBytes());
+        byte[] bytes = 
cipher.doFinal(content.getBytes(StandardCharsets.UTF_8));
         return byte2Base64(bytes);
     }
 
diff --git 
a/common/src/test/java/org/apache/seata/common/util/ConfigToolsTest.java 
b/common/src/test/java/org/apache/seata/common/util/ConfigToolsTest.java
index 6da65011c4..1f84002db1 100644
--- a/common/src/test/java/org/apache/seata/common/util/ConfigToolsTest.java
+++ b/common/src/test/java/org/apache/seata/common/util/ConfigToolsTest.java
@@ -184,11 +184,11 @@ public class ConfigToolsTest {
     }
 
     @Test
-    public void testRoundTripEncryption() throws Exception {
+    public void testRoundTripEncryptionWithUnicodeContent() throws Exception {
         KeyPair keyPair = ConfigTools.getKeyPair();
         String publicKeyStr = ConfigTools.getPublicKey(keyPair);
         String privateKeyStr = ConfigTools.getPrivateKey(keyPair);
-        String content = "This is a test message for encryption round trip";
+        String content = "This is a test message for encryption round trip: 
\u4e2d\u6587";
 
         // Public encrypt, private decrypt
         String encrypted1 = ConfigTools.publicEncrypt(content, publicKeyStr);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to