I have a seemingly simple task..
Take a file, open it, take the byte stream as a AES key, and instantiate a javax.crypto.spec.SecretKeySpec
within Android Kotlin
if (key == null) {
val my_bytes: ByteArray = byteArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
val algo = "AES"
val secretKey = SecretKeySpec(my_bytes, algo)
saveSecretKey(sharedPref, secretKey!!)
return secretKey
}
Edit: SecretKeySpec()
works now. I just need to know how to put the bytes from the file into the android app properly. Is hard coding in the app insecure? Should I store the key as a file and read it in from the android file system?
If you store the key as a file on the external drive the following things will happen:
Since secret key is symmetric, and can be used for both encryption and decryption.
Now, for our birds:
To load the file from the disk: This explains it quite well