AES Encrypt Decrypt
Closed this issue · 0 comments
gillangit commented
I am new to the world of encryption, I am trying to secure the jwt token in my small application, because it is made on a multiplatform I see the jwt stored in the datastore in raw form so it is easy to see, can you help me how to apply AES here, after I tried the example it turned out that it was no longer in accordance with the latest version
object AesCtrHelper {
private val provider = CryptographyProvider.Default
private val aesCtr = provider.get(AES.CTR)
suspend fun generateKey(): AES.CTR.Key = aesCtr.keyGenerator(keySize = AES.Key.Size.B256).generateKey()
suspend fun encrypt(key: AES.CTR.Key, data: ByteArray): ByteArray {
val cipher = key.cipher()
return cipher.encrypt(data)
}
suspend fun decrypt(key: AES.CTR.Key, ciphertext: ByteArray): ByteArray {
val cipher = key.cipher()
return cipher.decrypt(ciphertext)
}
}
how to save key as String? and convert string back to AES.CTR.Key