feat: js支持hex编码解码

pull/2440/head
Xwite 2 years ago
parent 95ec2200c1
commit 02582d2412
  1. 12
      app/src/main/assets/help/jsHelp.md
  2. 22
      app/src/main/java/io/legado/app/help/JsExtensions.kt

@ -132,8 +132,18 @@ java.getZipStringContent(url: String, path: String)
> flags参数可省略,默认Base64.NO_WRAP,查看[flags参数说明](https://blog.csdn.net/zcmain/article/details/97051870)
```
java.base64Decode(str: String, flags: Int)
java.base64DecodeToByteArray(str: String, flags: Int)
java.base64Encode(str: String, flags: Int)
```
* Hex
```
/* HexString 解码为字节数组 */
hexDecodeToByteArray(hex: String): ByteArray?
/* hexString 解码为utf8String*/
hexDecodeToString(hex: String): String?
/* utf8 编码为hexString */
hexEncodeToString(utf8: String): String?
```
* 文件
> 所有对于文件的读写删操作都是相对路径,只能操作阅读缓存/android/data/{package}/cache/内的文件
```
@ -163,7 +173,7 @@ deleteFile(path: String)
> TripleDES tansformation默认实现DESede/ECB/PKCS5Padding
> 内部实现为cn.hutool.crypto 解密加密接口支持ByteArray|Base64String|HexString|InputStream
> 输入参数key iv 支持ByteArray|Utf8String
> 如果key iv 为Hex Base64,且需要解码为ByteArray,调用java.decodeBase64Hex
> 如果key iv 为Hex Base64,且需要解码为ByteArray,自行调用java.base64DecodeToByteArray java.hexDecodeToByteArray
```
//解密为ByteArray 字符串
java.createSymmetricCrypto(transformation, key, iv).decrypt(data)

@ -319,7 +319,7 @@ interface JsExtensions {
}
/**
* js实现解码,不能删
* js实现base64解码,不能删
*/
fun base64Decode(str: String): String {
return EncoderUtils.base64Decode(str, Base64.NO_WRAP)
@ -351,6 +351,19 @@ interface JsExtensions {
return EncoderUtils.base64Encode(str, flags)
}
/* HexString 解码为字节数组 */
fun hexDecodeToByteArray(hex: String): ByteArray? {
return HexUtil.decodeHex(hex)
}
/* hexString 解码为utf8String*/
fun hexDecodeToString(hex: String): String? {
return HexUtil.decodeHexStr(hex)
}
/* utf8 编码为hexString */
fun hexEncodeToString(utf8: String): String? {
return HexUtil.encodeHexStr(hex)
}
/**
* 格式化时间
*/
@ -662,14 +675,7 @@ interface JsExtensions {
* java.createSymmetricCrypto(transformation, key, iv).encrypt(data)
* java.createSymmetricCrypto(transformation, key, iv).encryptBase64(data)
* java.createSymmetricCrypto(transformation, key, iv).encryptHex(data)
* 如果key iv 为Hex Base64,且需要解码为ByteArray调用java.decodeBase64Hex
*/
/* iv key 为Base64String HexString 到ByteArray的转换函数 */
fun decodeBase64Hex(str: String): ByteArray? {
return SecureUtil.decode(str)
}
/* 调用SymmetricCrypto key为null时使用随机密钥*/
fun createSymmetricCrypto(

Loading…
Cancel
Save