Skip to content

Instantly share code, notes, and snippets.

@BDOMDev
Last active June 26, 2019 08:43
Show Gist options
  • Save BDOMDev/759a5513d78713aebeec59a933518d6a to your computer and use it in GitHub Desktop.
Save BDOMDev/759a5513d78713aebeec59a933518d6a to your computer and use it in GitHub Desktop.
Encrypt a file
@Throws(Exception::class)
fun encrypt(yourKey: SecretKey, fileData: ByteArray): ByteArray {
val data = yourKey.getEncoded()
val skeySpec = SecretKeySpec(data, 0, data.size, "AES")
val cipher = Cipher.getInstance("AES", "BC")
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, IvParameterSpec(ByteArray(cipher.getBlockSize())))
return cipher.doFinal(fileData)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment