mirror of https://github.com/NekoX-Dev/NekoX.git
替换掉标准库的Base64
This commit is contained in:
parent
9718538290
commit
295af1fa46
|
@ -28,7 +28,7 @@ dependencies {
|
|||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5"
|
||||
|
||||
def okHttpVersion = '4.5.0'
|
||||
def okHttpVersion = '4.6.0'
|
||||
|
||||
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
|
||||
implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:$okHttpVersion"
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package com.v2ray.ang.dto
|
||||
|
||||
import android.util.Base64
|
||||
import cn.hutool.core.codec.Base64
|
||||
import com.google.gson.Gson
|
||||
import com.v2ray.ang.V2RayConfig
|
||||
import com.v2ray.ang.V2RayConfig.SS_PROTOCOL
|
||||
import com.v2ray.ang.V2RayConfig.VMESS_PROTOCOL
|
||||
import com.v2ray.ang.util.Utils
|
||||
|
||||
data class AngConfig(
|
||||
var index: Int,
|
||||
|
@ -57,15 +56,15 @@ data class AngConfig(
|
|||
vmessQRCode.path = path
|
||||
vmessQRCode.tls = streamSecurity
|
||||
|
||||
return VMESS_PROTOCOL + Utils.encode(Gson().toJson(vmessQRCode))
|
||||
return VMESS_PROTOCOL + cn.hutool.core.codec.Base64.encode(Gson().toJson(vmessQRCode))
|
||||
|
||||
} else if (configType == V2RayConfig.EConfigType.Shadowsocks) {
|
||||
|
||||
val remark = "#" + Utils.urlEncode(remarks)
|
||||
val remark = "#" + Base64.encodeUrlSafe(remarks)
|
||||
|
||||
val url = String.format("%s:%s@%s:%s", security, id, address, port)
|
||||
|
||||
return SS_PROTOCOL + Base64.encodeToString(url.toByteArray(charset("UTF-8")), Base64.NO_WRAP) + remark
|
||||
return SS_PROTOCOL + Base64.encode(url.toByteArray(charset("UTF-8"))) + remark
|
||||
|
||||
} else {
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.v2ray.ang.util
|
||||
|
||||
import android.text.TextUtils
|
||||
import android.util.Base64
|
||||
import org.json.JSONObject
|
||||
import cn.hutool.core.codec.Base64
|
||||
import org.telegram.messenger.ApplicationLoader
|
||||
import java.io.IOException
|
||||
import java.net.Socket
|
||||
|
@ -26,49 +25,6 @@ object Utils {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* base64 decode
|
||||
*/
|
||||
fun decode(text: String): String {
|
||||
return runCatching {
|
||||
Base64.decode(text, Base64.URL_SAFE or Base64.NO_WRAP).toString(charset("UTF-8"))
|
||||
}.recoverCatching {
|
||||
Base64.decode(text, Base64.NO_WRAP).toString(charset("UTF-8"))
|
||||
}.recoverCatching {
|
||||
Base64.decode(text, Base64.DEFAULT).toString(charset("UTF-8"))
|
||||
}.getOrThrow()
|
||||
}
|
||||
|
||||
fun decodeJson(text: String): String {
|
||||
return runCatching {
|
||||
Base64.decode(text, Base64.URL_SAFE or Base64.NO_WRAP).toString(charset("UTF-8")).also {
|
||||
JSONObject(it)
|
||||
}
|
||||
}.recoverCatching {
|
||||
Base64.decode(text, Base64.NO_WRAP).toString(charset("UTF-8")).also {
|
||||
JSONObject(it)
|
||||
}
|
||||
}.recoverCatching {
|
||||
Base64.decode(text, Base64.DEFAULT).toString(charset("UTF-8")).also {
|
||||
JSONObject(it)
|
||||
}
|
||||
}.getOrThrow()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* base64 encode
|
||||
*/
|
||||
fun encode(text: String): String {
|
||||
try {
|
||||
return Base64.encodeToString(text.toByteArray(charset("UTF-8")), Base64.NO_WRAP)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* is ip address
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package tw.nekomimi.nekogram
|
||||
|
||||
import android.util.Base64
|
||||
import cn.hutool.core.codec.Base64
|
||||
import com.v2ray.ang.V2RayConfig.SS_PROTOCOL
|
||||
import com.v2ray.ang.util.Utils
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
@ -10,7 +10,6 @@ import org.telegram.messenger.ApplicationLoader
|
|||
import org.telegram.messenger.FileLog
|
||||
import tw.nekomimi.nekogram.utils.FileUtil
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
|
@ -112,7 +111,7 @@ class ShadowsocksLoader {
|
|||
put("server", host)
|
||||
put("server_port", remotePort)
|
||||
put("password", password)
|
||||
put("method",method)
|
||||
put("method", method)
|
||||
put("ipv6", true)
|
||||
}
|
||||
|
||||
|
@ -139,7 +138,7 @@ class ShadowsocksLoader {
|
|||
|
||||
}
|
||||
|
||||
val methodAndPswd = Utils.decode(link.username)
|
||||
val methodAndPswd = Base64.decodeStr(link.username)
|
||||
|
||||
return Bean(
|
||||
link.host,
|
||||
|
@ -157,7 +156,7 @@ class ShadowsocksLoader {
|
|||
|
||||
if (v2Url.contains("#")) v2Url = v2Url.substringBefore("#")
|
||||
|
||||
val link = ("https://" + Utils.decode(v2Url.substringAfter(SS_PROTOCOL))).toHttpUrlOrNull()
|
||||
val link = ("https://" + Base64.decodeStr(v2Url.substringAfter(SS_PROTOCOL))).toHttpUrlOrNull()
|
||||
?: error("invalid v2rayNG link $url")
|
||||
|
||||
return Bean(
|
||||
|
@ -176,9 +175,9 @@ class ShadowsocksLoader {
|
|||
|
||||
override fun toString(): String {
|
||||
|
||||
var url = "ss://" + Base64.encode("$method:$password".toByteArray(),Base64.NO_WRAP or Base64.URL_SAFE) + "@$host:$remotePort"
|
||||
var url = "ss://" + Base64.encodeUrlSafe("$method:$password") + "@$host:$remotePort"
|
||||
|
||||
if (remarks?.isNotBlank() == true) url += "#" + Utils.urlEncode(remarks!!)
|
||||
if (remarks?.isNotBlank() == true) url += "#" + Base64.encodeUrlSafe(remarks!!)
|
||||
|
||||
return url
|
||||
|
||||
|
|
|
@ -140,26 +140,26 @@ class ShadowsocksRLoader {
|
|||
|
||||
fun parse(url: String): Bean {
|
||||
|
||||
val params = Utils.decode(url.substringAfter(SSR_PROTOCOL)).split(":")
|
||||
val params = Base64.decodeStr(url.substringAfter(SSR_PROTOCOL)).split(":")
|
||||
|
||||
val bean = Bean(params[0],
|
||||
params[1].toInt(),
|
||||
protocol = params[2],
|
||||
method = params[3],
|
||||
obfs = params[4],
|
||||
password = Utils.decode(params[5].substringBefore("/")))
|
||||
password = Base64.decodeStr(params[5].substringBefore("/")))
|
||||
|
||||
val httpUrl = ("https://localhost" + params[5].substringAfter("/")).toHttpUrl()
|
||||
|
||||
runCatching {
|
||||
|
||||
bean.obfs_param = Utils.decode(httpUrl.queryParameter("obfsparam")!!)
|
||||
bean.obfs_param = Base64.decodeStr(httpUrl.queryParameter("obfsparam")!!)
|
||||
|
||||
}
|
||||
|
||||
runCatching {
|
||||
|
||||
bean.protocol_param = Utils.decode(httpUrl.queryParameter("protoparam")!!)
|
||||
bean.protocol_param = Base64.decodeStr(httpUrl.queryParameter("protoparam")!!)
|
||||
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ class ShadowsocksRLoader {
|
|||
|
||||
if (remarks?.isNotBlank() == true) {
|
||||
|
||||
bean.remarks = Utils.decode(remarks)
|
||||
bean.remarks = Base64.decodeStr(remarks)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package tw.nekomimi.nekogram
|
||||
|
||||
import cn.hutool.core.codec.Base64
|
||||
import com.google.gson.Gson
|
||||
import com.v2ray.ang.V2RayConfig
|
||||
import com.v2ray.ang.V2RayConfig.SOCKS_PROTOCOL
|
||||
|
@ -103,7 +104,7 @@ class VmessLoader {
|
|||
} else {
|
||||
|
||||
var result = server.replace(VMESS_PROTOCOL, "")
|
||||
result = Utils.decodeJson(result)
|
||||
result = Base64.decodeStr(result)
|
||||
if (result.isBlank()) {
|
||||
error("invalid url format")
|
||||
}
|
||||
|
@ -166,9 +167,9 @@ class VmessLoader {
|
|||
//part decode
|
||||
val indexS = result.indexOf("@")
|
||||
if (indexS > 0) {
|
||||
result = Utils.decode(result.substring(0, indexS)) + result.substring(indexS, result.length)
|
||||
result = Base64.decodeStr(result.substring(0, indexS)) + result.substring(indexS, result.length)
|
||||
} else {
|
||||
result = Utils.decode(result)
|
||||
result = Base64.decodeStr(result)
|
||||
}
|
||||
|
||||
val legacyPattern = "^(.+?):(.*)@(.+?):(\\d+?)$".toRegex()
|
||||
|
@ -198,7 +199,7 @@ class VmessLoader {
|
|||
//part decode
|
||||
val indexS = result.indexOf(":")
|
||||
if (indexS < 0) {
|
||||
result = Utils.decode(result)
|
||||
result = Base64.decodeStr(result)
|
||||
}
|
||||
|
||||
val legacyPattern = "^(.+?):(\\d+?)$".toRegex()
|
||||
|
@ -342,7 +343,7 @@ class VmessLoader {
|
|||
if (indexSplit > 0) {
|
||||
result = result.substring(0, indexSplit)
|
||||
}
|
||||
result = Utils.decode(result)
|
||||
result = Base64.decodeStr(result)
|
||||
|
||||
val arr1 = result.split('@')
|
||||
if (arr1.count() != 2) {
|
||||
|
|
|
@ -10,11 +10,11 @@ import android.content.pm.PackageManager
|
|||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.util.Base64
|
||||
import android.view.Gravity
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Toast
|
||||
import cn.hutool.core.codec.Base64
|
||||
import cn.hutool.core.util.StrUtil
|
||||
import com.google.zxing.*
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer
|
||||
|
@ -33,7 +33,7 @@ import java.io.ByteArrayInputStream
|
|||
import java.io.File
|
||||
import java.net.NetworkInterface
|
||||
import java.util.*
|
||||
|
||||
import kotlin.collections.HashMap
|
||||
|
||||
object ProxyUtil {
|
||||
|
||||
|
@ -107,7 +107,7 @@ object ProxyUtil {
|
|||
|
||||
val text = runCatching {
|
||||
|
||||
StrUtil.utf8Str(Base64.decode(_text, Base64.DEFAULT))
|
||||
Base64.decodeStr(_text)
|
||||
|
||||
}.recover {
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ buildscript {
|
|||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.0-alpha06'
|
||||
classpath 'com.android.tools.build:gradle:4.1.0-alpha08'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
|
||||
classpath 'com.google.gms:google-services:4.3.3'
|
||||
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta04'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Sun Apr 19 13:54:05 CST 2020
|
||||
#Thu Apr 30 00:19:49 CST 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-rc-1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-rc-3-all.zip
|
||||
|
|
Loading…
Reference in New Issue