2dust
2025-10-03 14:28:31 +08:00
parent 305219c3bc
commit edea3027f7
3 changed files with 9 additions and 4 deletions

View File

@@ -122,7 +122,7 @@ object ShadowsocksFmt : FmtBase() {
fun toUri(config: ProfileItem): String {
val pw = "${config.method}:${config.password}"
return toUri(config, Utils.encode(pw), null)
return toUri(config, Utils.encode(pw, true), null)
}
/**

View File

@@ -51,7 +51,7 @@ object SocksFmt : FmtBase() {
else
":"
return toUri(config, Utils.encode(pw), null)
return toUri(config, Utils.encode(pw, true), null)
}
/**

View File

@@ -134,11 +134,16 @@ object Utils {
* Encode a string to base64.
*
* @param text The string to encode.
* @param removePadding
* @return The base64 encoded string, or an empty string if encoding fails.
*/
fun encode(text: String): String {
fun encode(text: String, removePadding : Boolean = false): String {
return try {
Base64.encodeToString(text.toByteArray(Charsets.UTF_8), Base64.NO_WRAP)
var encoded = Base64.encodeToString(text.toByteArray(Charsets.UTF_8), Base64.NO_WRAP)
if (removePadding) {
encoded = encoded.trimEnd('=')
}
encoded
} catch (e: Exception) {
Log.e(AppConfig.TAG, "Failed to encode text to base64", e)
""