aes算法对key的字节数有要求 所以对输入的key要做填充处理
fun fillKey(key: String): ByteArray {
val random = SecureRandom.getInstance("SHA1PRNG")
random.setSeed(key.toByteArray())
val generator = KeyGenerator.getInstance("AES")
generator.init(random)
return generator.generateKey().encoded
}
fun ktAes(key: String, source: String): String {
val keyBytes = fillKey(key)
return Aes(keyBytes).encryptBase64(source)
}
fun ktDeAes(key: String, source: String): String {
val keyBytes = fillKey(key)
return Aes(keyBytes).decryptStr(source)
}