Use Facebook Conceal To Encrypt And Decrypt String (Kotlin)

Setup Facebook Conceal.

Encrypt string

var encryptedData = crypto.encrypt(value.toByteArray(Charsets.UTF_8), Entity.create("Test"))encryptedData = Base64.encodeToString(encryptedData, Base64.DEFAULT)

Decrypt string

var value = crypto.decrypt(Base64.decode(encryptedData, Base64.DEFAULT), Entity.create("Test"))value.toString(Charsets.UTF_8)

You can write an Kotlin Extentions to encrypt and decrypt string using Facebook Conceal.

fun Crypto.encrypt(key: String, value: String): String {    val data = encrypt(value.toByteArray(Charsets.UTF_8), Entity.create(key))    return Base64.encodeToString(data, Base64.DEFAULT)}fun Crypto.decrypt(key: String, value: String): String {    val data = decrypt(Base64.decode(value, Base64.DEFAULT), Entity.create(key))    return data.toString(Charsets.UTF_8)}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.