pyshiweijia opened a new issue, #8168: URL: https://github.com/apache/incubator-seata/issues/8168
### Check Ahead - [x] I have searched the [issues](https://github.com/seata/seata/issues) of this repository and believe that this is not a duplicate. - [x] I am willing to try to fix this bug myself. ### Ⅰ. Issue Description `ConfigTools.publicEncrypt` and `ConfigTools.privateEncrypt` convert plaintext with `String.getBytes()`, which uses the platform-default charset. Both decrypt methods decode the recovered bytes as UTF-8. The mismatch corrupts non-ASCII content when the default charset is not UTF-8. ### Ⅱ. Describe what happened On Windows with a GBK default charset, an RSA round trip changes the plaintext `中文` to `????`. ```java KeyPair keyPair = ConfigTools.getKeyPair(); String publicKey = ConfigTools.getPublicKey(keyPair); String privateKey = ConfigTools.getPrivateKey(keyPair); String content = "\u4e2d\u6587"; String encrypted = ConfigTools.publicEncrypt(content, publicKey); assertThat(ConfigTools.privateDecrypt(encrypted, privateKey)).isEqualTo(content); ``` ```text expected: "中文" but was: "????" ``` The private-encrypt/public-decrypt path has the same encoding mismatch. ### Ⅲ. Describe what you expected to happen Both encryption paths should encode plaintext as UTF-8, matching the existing UTF-8 decoding in the decryption paths. RSA round trips should preserve Unicode content on every supported platform. ### Ⅳ. How to reproduce it (as minimally and precisely as possible) 1. Run on a platform whose default charset is not UTF-8, such as Windows with GBK. 2. Add the test above to `ConfigToolsTest`. 3. Run `mvn -pl common -am test -Dtest=ConfigToolsTest -Dlicense.skip=true -B`. ### Ⅴ. Anything else we need to know? A minimal fix is to use `content.getBytes(StandardCharsets.UTF_8)` in both encryption methods. ASCII behavior remains unchanged. A regression test and implementation are ready on branch `pyshiweijia:bugfix/config-tools-utf8`. ### Ⅵ. Environment - Branch: `2.x` - Revision: `e6d0860a4345b10cb59c65c78215ec51d67f59d1` - JDK: Oracle JDK 17.0.14; targeted regression also passes after the fix on JDK 8u202 - Maven: 3.8.4 - OS: Windows 11 amd64 - Default charset: GBK -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
