Last active
June 16, 2023 13:08
-
-
Save qamarelsafadi/19d7e1688e100007e35959884b575733 to your computer and use it in GitHub Desktop.
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
class MainActivity : AppCompatActivity() { | |
lateinit var encryptor: Encryptor | |
private val SAMPLE_ALIAS = BuildConfig.MY_ALIAS // save your ALIAS key in local.properties for more security | |
init { | |
encryptText() | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
MyApplicationTheme { | |
// A surface container using the 'background' color from the theme | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { | |
Greeting(decryptText()) | |
} | |
} | |
} | |
} | |
private fun encryptText() { | |
try { | |
encryptor = EnCryptor() | |
val encryptedText = encryptor.encryptText(SAMPLE_ALIAS, BuildConfig.SECRET_KEY) // your secret key form local.properties | |
Base64.encodeToString(encryptedText, Base64.DEFAULT) | |
} catch (e: Exception) { | |
Log.e("TAG", e.message, e) | |
} | |
} | |
private fun decryptText():String { | |
val deCryptor = Decryptor() | |
try { | |
val secretKey = deCryptor.decryptData(SAMPLE_ALIAS, encryptor.encryption, encryptor.iv) | |
return secretKey | |
} catch (e: Exception) { | |
Log.e("TAG", e.message, e) | |
return e.message.toString() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment