代码拉取完成,页面将自动刷新
库引用: 替换1.3.1 为最新版本
implementation 'com.gitee.zhangmengxiong:MXKeyValue:1.3.1'
val KV = MXKeyValue.Builder("kvdb_kv_v1")
.setCrypt(KVAESCrypt("27e2125d0a11a9aa65b9c9773673bc2a"))
.setStore(KVSqliteStore())
.build(MyApp.appContext)
// 清理所有KV
KV.cleanAll()
// 获取所有KV
KV.getAll()
// 清理失效的KeyValue
KV.cleanExpire()
// 设置KV
KV.set(key, value)
// 设置KV的有效期 1分钟 后失效
KV.set(key, value, 1.toDuration(DurationUnit.MINUTES))
// 获取Value
KV.get("test_expire_key")
// 获取Value ,如果不存在则返回默认值
KV.get("test_expire_key", default = "默认值")
// 删除key
KV.delete("test_expire_key")
// 从SharedPreferences拷贝所有数据
KV.cloneFromSharedPreferences("sp_name")
MXKeyValue内置两种加密方式:
KVNoCrypt = 不加密,存储Value=设置的Value
KVAESCrypt = AES对称加密
注意:KVAESCrypt初始化的加密字符在app上线后不能修改,否则会导致数据读取错误!
class MyCrypt : IKVCrypt {
private val divider = "$$$$$$$$$$$$"
override fun generalSalt(): String {
return UUID.randomUUID().toString().replace("-", "")
}
override fun encrypt(key: String, value: String, salt: String): String? {
return "$key$divider$value"
}
override fun decrypt(key: String, secretValue: String, salt: String): String? {
return secretValue.split(divider).lastOrNull()
}
}
使用方法:
val KV = MXKeyValue.Builder(MyApp.appContext, "kvdb_kv_v1")
.setCrypt(MyCrypt())
.setStore(KVSqliteStore())
.build()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。