|
|
@ -7,6 +7,7 @@ import cn.hutool.crypto.digest.DigestUtil |
|
|
|
import cn.hutool.crypto.digest.HMac |
|
|
|
import cn.hutool.crypto.digest.HMac |
|
|
|
import cn.hutool.core.util.HexUtil |
|
|
|
import cn.hutool.core.util.HexUtil |
|
|
|
import cn.hutool.crypto.symmetric.SymmetricCrypto |
|
|
|
import cn.hutool.crypto.symmetric.SymmetricCrypto |
|
|
|
|
|
|
|
import cn.hutool.crypto.SecureUtil |
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.constant.AppConst.dateFormat |
|
|
|
import io.legado.app.constant.AppConst.dateFormat |
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
import io.legado.app.constant.AppLog |
|
|
@ -658,51 +659,50 @@ interface JsExtensions { |
|
|
|
* java.createSymmetricCrypto(transformation, key, iv).encrypt(data) |
|
|
|
* java.createSymmetricCrypto(transformation, key, iv).encrypt(data) |
|
|
|
* java.createSymmetricCrypto(transformation, key, iv).encryptBase64(data) |
|
|
|
* java.createSymmetricCrypto(transformation, key, iv).encryptBase64(data) |
|
|
|
* java.createSymmetricCrypto(transformation, key, iv).encryptHex(data) |
|
|
|
* java.createSymmetricCrypto(transformation, key, iv).encryptHex(data) |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 自动转换key iv 到ByteArray 支持base64 hex uft8*/ |
|
|
|
* 如果key iv 为Hex Base64,且需要解码为ByteArray,调用java.decodeBase64Hex |
|
|
|
fun createSymmetricCrypto( |
|
|
|
|
|
|
|
transformation: String, |
|
|
|
*/ |
|
|
|
key: String |
|
|
|
/* iv key 为Base64String HexString 到ByteArray的转换函数 */ |
|
|
|
): SymmetricCrypto { |
|
|
|
fun decodeBase64Hex(str: String): ByteArray? { |
|
|
|
return createSymmetricCrypto(transformation, key, null) |
|
|
|
return SecureUtil.decode(str) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 调用SymmetricCrypto key为null时使用随机密钥*/ |
|
|
|
fun createSymmetricCrypto( |
|
|
|
fun createSymmetricCrypto( |
|
|
|
transformation: String, |
|
|
|
transformation: String, |
|
|
|
key: String, |
|
|
|
key: ByteArray?, |
|
|
|
iv: String? |
|
|
|
iv: ByteArray? |
|
|
|
): SymmetricCrypto { |
|
|
|
): SymmetricCrypto { |
|
|
|
return createSymmetricCrypto( |
|
|
|
val symmetricCrypto = SymmetricCrypto(transformation, key) |
|
|
|
transformation, |
|
|
|
return if (iv != null && !iv.isEmpty()) symmetricCrypto.setIv(iv) else symmetricCrypto |
|
|
|
StringUtils.encodeStringToByteArray(key), |
|
|
|
|
|
|
|
StringUtils.encodeStringToByteArray(iv) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* 调用SymmetricCrypto key为null时使用随机密钥*/ |
|
|
|
|
|
|
|
fun createSymmetricCrypto( |
|
|
|
fun createSymmetricCrypto( |
|
|
|
transformation: String |
|
|
|
transformation: String, |
|
|
|
|
|
|
|
key: ByteArray |
|
|
|
): SymmetricCrypto { |
|
|
|
): SymmetricCrypto { |
|
|
|
return createSymmetricCrypto(transformation, null, null) |
|
|
|
return createSymmetricCrypto(transformation, key, null) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun createSymmetricCrypto( |
|
|
|
fun createSymmetricCrypto( |
|
|
|
transformation: String, |
|
|
|
transformation: String, |
|
|
|
key: ByteArray |
|
|
|
key: String |
|
|
|
): SymmetricCrypto { |
|
|
|
): SymmetricCrypto { |
|
|
|
return createSymmetricCrypto(transformation, key, null) |
|
|
|
return createSymmetricCrypto(transformation, key, null) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun createSymmetricCrypto( |
|
|
|
fun createSymmetricCrypto( |
|
|
|
transformation: String, |
|
|
|
transformation: String, |
|
|
|
key: ByteArray?, |
|
|
|
key: String, |
|
|
|
iv: ByteArray? |
|
|
|
iv: String? |
|
|
|
): SymmetricCrypto { |
|
|
|
): SymmetricCrypto { |
|
|
|
val symmetricCrypto = SymmetricCrypto(transformation, key) |
|
|
|
return createSymmetricCrypto( |
|
|
|
return if (iv != null && !iv.isEmpty()) symmetricCrypto.setIv(iv) else symmetricCrypto |
|
|
|
transformation, key.encodeToByteArray(), iv?.encodeToByteArray() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//******************消息摘要/散列消息鉴别码************************// |
|
|
|
//******************消息摘要/散列消息鉴别码************************// |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|