Commit 47b8bf8a authored by wanglei's avatar wanglei

+干掉混淆+和加密。

parent 753a3ce7
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
package com.test.easy.easycleanerjunk.helps
import android.util.Base64
import java.security.SecureRandom
import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec
object AESHelper {
private const val aesKey = "r07y7is0zk7bej34"
private val cipher by lazy {
Cipher.getInstance("AES/GCM/NoPadding")
}
fun encrypt(content: String): String {
try {
val iv = ByteArray(12).apply {
SecureRandom().nextBytes(this)
}
val contentBytes = content.toByteArray(Charsets.UTF_8)
val params = GCMParameterSpec(128, iv)
cipher.init(
Cipher.ENCRYPT_MODE,
secretKey, params
)
val encryptData = cipher.doFinal(contentBytes)
assert(encryptData.size == contentBytes.size + 16)
val message = ByteArray(12 + contentBytes.size + 16)
System.arraycopy(iv, 0, message, 0, 12)
System.arraycopy(encryptData, 0, message, 12, encryptData.size)
return String(Base64.encode(message, Base64.NO_WRAP), Charsets.UTF_8)
} catch (_: Exception) {
}
return content
}
@Synchronized
fun decrypt(content: String): String {
try {
val con = content.replace(" ".toRegex(), "+")
val contentByte = Base64.decode(con, Base64.NO_WRAP)
require(contentByte.size >= 12 + 16)
val params = GCMParameterSpec(128, contentByte, 0, 12)
cipher.init(
Cipher.DECRYPT_MODE,
secretKey, params
)
val decryptData = cipher.doFinal(contentByte, 12, contentByte.size - 12)
return String(decryptData, Charsets.UTF_8)
} catch (_: Exception) {
}
return content
}
private val secretKey by lazy {
SecretKeySpec(aesKey.toByteArray(), "AES")
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.helps
import android.content.Context
import android.util.AttributeSet
import com.noober.background.view.BLTextView
import com.test.easy.easycleanerjunk.helps.KotlinExt.decode
class AESTextView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : BLTextView(context, attrs) {
override fun setText(text: CharSequence?, type: BufferType?) {
super.setText(text?.toString()?.run { decode().takeIf { it != this } } ?: text, type)
}
}
\ No newline at end of file
...@@ -29,7 +29,7 @@ object ComUtils { ...@@ -29,7 +29,7 @@ object ComUtils {
} }
fun getLocalConfigBean(): ConfigBean { fun getLocalConfigBean(): ConfigBean {
val json = AESHelper.decrypt(localConfig) val json = localConfig
LogEx.logDebug(TAG, "Local json=$json") LogEx.logDebug(TAG, "Local json=$json")
val configBean = GsonUtils.fromJson(json, ConfigBean::class.java) val configBean = GsonUtils.fromJson(json, ConfigBean::class.java)
LogEx.logDebug(TAG, "Local configBean=$configBean") LogEx.logDebug(TAG, "Local configBean=$configBean")
......
...@@ -8,24 +8,6 @@ import java.util.Locale ...@@ -8,24 +8,6 @@ import java.util.Locale
object KotlinExt { object KotlinExt {
private val aesMap = mutableMapOf<Int, String>()
fun Int.string(vararg arg: Any) = try {
(aesMap[this] ?: BaseApplication.context.getString(this).decode()).run {
aesMap[this@string] = this
String.format(this, *arg)
}
} catch (_: Exception) {
""
}
fun String.decode() = AESHelper.decrypt(this)
.replace("\\r", "\r")
.replace("\\n", "\n")
.replace("\\'", "'")
.replace("\\\"", "\"")
.replace("\\?", "?")
.replace("&amp;", "&")
fun Collection<View>.setOnClickListener(listener: (View) -> Unit) { fun Collection<View>.setOnClickListener(listener: (View) -> Unit) {
this.forEach { this.forEach {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment