Skip to content

Instantly share code, notes, and snippets.

View luisenricke's full-sized avatar

Luis Villalobos luisenricke

View GitHub Profile
@luisenricke
luisenricke / sha_aes_utility.kt
Created October 9, 2019 05:25 — forked from reuniware/sha_aes_utility.kt
Android Kotlin : SHA-1 Hash and AES Encryption/Decryption and Storing password, secretKey, IV and Hash in Shared Preferences
fun hashAndSavePasswordHash(context: Context, clearPassword: String) {
val digest = MessageDigest.getInstance("SHA-1")
val result = digest.digest(clearPassword.toByteArray(Charsets.UTF_8))
val sb = StringBuilder()
for (b in result) {
sb.append(String.format("%02X", b))
}
val hashedPassword = sb.toString()
val sharedPref = PreferenceManager.getDefaultSharedPreferences(context)
val editor = sharedPref.edit()