Last active
June 26, 2019 08:43
-
-
Save BDOMDev/759a5513d78713aebeec59a933518d6a to your computer and use it in GitHub Desktop.
Encrypt a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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