fix: StandardCharsets.UTF_8 替换为 Charset.forName("UTF-8")

Android 4.2(API 17)不支持 java.nio.charset.StandardCharsets(API 19+),
5 个文件统一改用兼容 API 1 的 String 重载:
- DeviceIdentityProvider / HMacShaUtils / Md5Utils: Charset.forName
- UrlParamBuilder: URLEncoder.encode(str, "UTF-8")
- ContentDetailUtils: 删除未使用的 import
This commit is contained in:
zhaogd
2026-08-26 15:51:33 +08:00
parent fca025383c
commit ccc65afcbc
6 changed files with 28 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
package com.pukka.libcore.cipher;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@@ -29,7 +29,7 @@ public class HMacShaUtils {
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA256_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
mac.init(signingKey);
return mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
return mac.doFinal(data.getBytes(Charset.forName("UTF-8")));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
@@ -51,7 +51,7 @@ public class HMacShaUtils {
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
return mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
return mac.doFinal(data.getBytes(Charset.forName("UTF-8")));
} catch (Exception ex) {
ex.printStackTrace();
}

View File

@@ -2,7 +2,7 @@ package com.pukka.libcore.cipher;
import com.pukka.libcore.utils.ByteConversionUtils;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.security.MessageDigest;
/**
@@ -61,7 +61,7 @@ public class Md5Utils {
public static String encrypt(String message) {
String md5str = "";
try {
md5str = encrypt(message.getBytes(StandardCharsets.UTF_8));
md5str = encrypt(message.getBytes(Charset.forName("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
}