feat(JsExtensions): add Hmac and update docs

pull/1902/head
Xwite 3 years ago
parent 620bd6a749
commit 123b9aacf2
  1. 32
      app/src/main/assets/help/jsHelp.md
  2. 4
      app/src/main/assets/updateLog.md
  3. 34
      app/src/main/java/io/legado/app/help/JsExtensions.kt

@ -54,7 +54,11 @@ java.put(key, value)
java.ajax(urlStr): String
java.ajaxAll(urlList: Array<String>): Array<StrResponse?>
//返回Response 方法body() code() message() header() raw() toString()
java.connect(urlStr): Response<String>
java.connect(urlStr): StrResponse
java.post(url: String, body: String, headerMap: Map<String, String>): Connection.Response
java.get(url: String, headerMap: Map<String, String>): Connection.Response
java.head(url: String, headerMap: Map<String, String>): Connection.Response
* 使用webView访问网络
* @param html 直接用webView载入的html, 如果html为空直接访问url
@ -130,11 +134,8 @@ deleteFile(path: String)
> [常见加密解密算法介绍](https://www.yijiyong.com/algorithm/encryption/01-intro.html)
> [相关概念](https://blog.csdn.net/OrangeJack/article/details/82913804)
* AES
> transformation默认实现AES/ECB/PKCS5Padding
```
* @param data 传入的原始数据
* @param key AES加密的key
* @param transformation AES加密的方式 例如AES/ECB/PKCS5Padding
* @param iv ECB模式的偏移向量
java.aesDecodeToString(str: String, key: String, transformation: String, iv: String)
java.aesBase64DecodeToString(str: String, key: String, transformation: String, iv: String)
@ -144,6 +145,7 @@ java.aesEncodeToString(str: String, key: String, transformation: String, iv: Str
java.aesEncodeToBase64String(str: String, key: String, transformation: String, iv: String)
```
* DES
> transformation默认实现DES/ECB/PKCS5Padding
```
java.desDecodeToString(str: String, key: String, transformation: String, iv: String)
@ -154,23 +156,25 @@ java.desEncodeToString(str: String, key: String, transformation: String, iv: Str
java.desEncodeToBase64String(str: String, key: String, transformation: String, iv: String)
```
* 3DES
> tansformation默认实现DESede/ECB/PKCS5Padding
```
* @param data 被加密的字符串
* @param key 密钥
* @param mode 模式 ECB/CBC/CFB/OFB/CTR
* @param padding 补码方式 NoPadding/PKCS5Padding/
* @param iv 加盐
java.tripleDESEncodeBase64Str(data: String,key: String,mode: String,padding: String,iv: String): String?
java.tripleDESDecodeStr(data: String,key: String,mode: String,padding: String,iv: String): String?
```
* 摘要
> algorithm支持MD2 MD5 SHA-1 SHA-256 SHA-384 SHA-512
```
java.digestHex(data: String, algorithm: String,): String?
java.digestBase64Str(data: String, algorithm: String,): String?
```
* HMac(散列消息鉴别码)
> algorithm支持HmacMD5 HmacSHA1 HmacSHA224 HmacSHA256 HmacSHA384 HmacSHA512
```
* @param data 被摘要数据
* @param algorithm 签名算法 MD5/SHA1/SHA256/SHA512
java.digestHex(data: String,algorithm: String,): String?
java.HMacHex(data: String, algorithm: String, key: String): String
java.digestBase64Str(data: String,algorithm: String,): String?
java.HMacBase64(data: String, algorithm: String, key: String): String
```
* md5
```

@ -15,6 +15,8 @@
* 修复部分txt章节结尾乱码bug
* 优化翻页流畅度
* js添加des HMac
* 登录ui用户信息默认加密方式改变,需要重新登录
**2022/05/21**
@ -322,4 +324,4 @@ eval(String(java.cacheFile(url)))
**2022/01/01**
* 修复本地txt问题,不在拷贝到私有目录,可以正常打开
* 优化txt目录识别,取目录数量最多的规则
* 优化txt目录识别,取目录数量最多的规则

@ -947,7 +947,7 @@ interface JsExtensions {
)?.let { String(it) }
}
//******************消息摘要************************//
//******************消息摘要/散列消息鉴别码************************//
/**
* 生成摘要并转为16进制字符串
@ -977,6 +977,38 @@ interface JsExtensions {
return Base64.encodeToString(DigestUtils.getDigest(algorithm, data.toByteArray()), Base64.NO_WRAP)
}
/**
* 生成散列消息鉴别码并转为16进制字符串
*
* @param data 被摘要数据
* @param algorithm 签名算法
* @param key 密钥
* @return 16进制字符串
*/
fun HMacHex(
data: String,
algorithm: String,
key: String
): String {
return DigestUtils.getHMac(algorithm, key, data)
}
/**
* 生成散列消息鉴别码并转为Base64字符串
*
* @param data 被摘要数据
* @param algorithm 签名算法
* @param key 密钥
* @return Base64字符串
*/
fun HMacBase64(
data: String,
algorithm: String,
key: String
): String {
return Base64.encodeToString(DigestUtils.getHMac(algorithm, key.toByteArray(), data.toByteArray()), Base64.NO_WRAP)
}
fun md5Encode(str: String): String {
return MD5Utils.md5Encode(str)
}

Loading…
Cancel
Save