I have used openssl_public_encrypt
function in a PHP-based server to encrypt a message with a public key. The crypted message is sent to a Kotlin-based server. If it were in PHP, the decryption would be done by using openssl_private_decrypt
. How can I decrypt the message in Kotlin?
So I found the equivalent code in Kotlin:
private fun decrypt(cryptedData: ByteArray): String {
val cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding") //"PKCS1Padding" is the default padding
cipher.init(Cipher.DECRYPT_MODE, key)
val res = cipher.doFinal(cryptedData).toHexString()
val decrypted = hexToAscii(res)
return decrypted
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.