SHARE
TWEET

Untitled

a guest Jun 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private const val TRANSFORMATION = "RSA/ECB/PKCS1Padding"
  2.  
  3. internal fun rsaEncrypt(data: String, keyPair: KeyPair): String {
  4.     val cipher = Cipher.getInstance(TRANSFORMATION)
  5.     cipher.init(Cipher.ENCRYPT_MODE, keyPair.private)
  6.     val bytes = cipher.doFinal(data.toByteArray(Charsets.UTF_8))
  7.     return Base64.encodeToString(bytes, 0)
  8. }
  9.      
  10. internal fun rsaDecrypt(data: String, keyPair: KeyPair): String {
  11.     val cipher = Cipher.getInstance(TRANSFORMATION)
  12.     cipher.init(Cipher.DECRYPT_MODE, keyPair.public)
  13.     val bytes = Base64.decode(data, 0)
  14.     val decrypted = cipher.doFinal(bytes)
  15.     return String(decrypted, Charsets.UTF_8)
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top