Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private const val TRANSFORMATION = "RSA/ECB/PKCS1Padding"
- internal fun rsaEncrypt(data: String, keyPair: KeyPair): String {
- val cipher = Cipher.getInstance(TRANSFORMATION)
- cipher.init(Cipher.ENCRYPT_MODE, keyPair.private)
- val bytes = cipher.doFinal(data.toByteArray(Charsets.UTF_8))
- return Base64.encodeToString(bytes, 0)
- }
- internal fun rsaDecrypt(data: String, keyPair: KeyPair): String {
- val cipher = Cipher.getInstance(TRANSFORMATION)
- cipher.init(Cipher.DECRYPT_MODE, keyPair.public)
- val bytes = Base64.decode(data, 0)
- val decrypted = cipher.doFinal(bytes)
- return String(decrypted, Charsets.UTF_8)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement