Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. fun encryptAES(cleartext: String, iv: ByteArray?, secret: SecretKeySpec): String {
  2. val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
  3. cipher.init(Cipher.ENCRYPT_MODE, secret, if (iv == null) null else IvParameterSpec(iv))
  4. val ciphertext = cipher.doFinal(cleartext.toByteArray(charset("UTF-8")))
  5. return Base64.encodeToString(ciphertext, Base64.NO_WRAP)
  6. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement