更新非对称加密
This commit is contained in:
@@ -31,25 +31,23 @@ class AsymmetricCrypto(algorithm: String) : HutoolAsymmetricCrypto(algorithm) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> cryptoDelegate(
|
private fun <T?> cryptoDelegate(
|
||||||
data: Any,
|
data: Any,
|
||||||
keyType: Int,
|
func: (Any) -> T?
|
||||||
func: (Any, KeyType) -> T
|
): T? {
|
||||||
): T {
|
|
||||||
val keyType = getKeyType(keyType)
|
|
||||||
return when {
|
return when {
|
||||||
data is ByteArray -> func.invoke(data, keyType)
|
data is ByteArray -> func.invoke(data as ByteArray)
|
||||||
data is String -> func.invoke(data, keyType)
|
data is String -> func.invoke(data as String)
|
||||||
data is InputStream -> func.invoke(data, keyType)
|
data is InputStream -> func.invoke(data as InputStream)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun decrypt(data: Any, keyType: Int): ByteArray? = cryptoDelegate<ByteArray?>(data, keyType, decrypt)
|
fun decrypt(data: Any, keyType: Int): ByteArray? = cryptoDelegate<ByteArray?>(data) { decrypt(it, getKeyType(keyType)) }
|
||||||
fun decryptStr(data: Any, keyType: Int): String? = cryptoDelegate<String?>(data, keyType, decryptStr)
|
fun decryptStr(data: Any, keyType: Int): String? = cryptoDelegate<String?>(data) { decryptStr(it, getKeyType(keyType)) }
|
||||||
|
|
||||||
fun encrypt(data: Any, keyType: Int): ByteArray? = cryptoDelegate<ByteArray?>(data, keyType, encrypt)
|
fun encrypt(data: Any, keyType: Int): ByteArray? = cryptoDelegate<ByteArray?>(data) { encrypt(it, getKeyType(keyType)) }
|
||||||
fun encryptHex(data: Any, keyType: Int): String? = cryptoDelegate<String?>(data, keyType, encryptHex)
|
fun encryptHex(data: Any, keyType: Int): String? = cryptoDelegate<String?>(data) { encryptHex(it, getKeyType(keyType)) }
|
||||||
fun encryptBase64(data: Any, keyType: Int): String? =cryptoDelegate<String?>(data, keyType, encryptBase64)
|
fun encryptBase64(data: Any, keyType: Int): String? =cryptoDelegate<String?>(data) { encryptBase64(it, getKeyType(keyType)) }
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user