Skip to content

Instantly share code, notes, and snippets.

View zukopvd's full-sized avatar

Sergey zukopvd

View GitHub Profile
@zukopvd
zukopvd / Encryptor.kt
Created January 29, 2018 09:02
Android Encryptor (Helper class)
class Encryptor(private val sharedPreferences: SharedPreferences) {
private val ANDROID_KEY_STORE = "AndroidKeyStore"
private var initVector: ByteArray? = null
private var encryption: ByteArray? = null
private val TRANSFORMATION = "AES/GCM/NoPadding"
@Throws(Exception::class)
fun encryptTextWithAES(alias: String, textToEncrypt: String): ByteArray? {
var alias = alias
@zukopvd
zukopvd / Decryptor.kt
Created January 29, 2018 09:05
Android Decryptor (Helper class)
class Decryptor(private val storage: SharedPreferences) {
private val ANDROID_KEY_STORE = "AndroidKeyStore"
private val TRANSFORMATION = "AES/GCM/NoPadding"
private var keyStore: KeyStore? = null
init {
initKeyStore()
}
@zukopvd
zukopvd / FingerprintManagerInit.kt
Created January 29, 2018 09:07
FingerprintManager initialization
val fmanager = FingerprintManagerCompat.from(getApplicationContext())
fmanager.authenticate(cryptoObject, 0, cancellationSignal, authenticationCallback, null)
@zukopvd
zukopvd / AuthenticationCallback.kt
Created January 29, 2018 09:10
Fingerprint AuthenticationCallback description
override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) {
//scanning completed with unknown error
}
override fun onAuthenticationSucceeded(result: FingerprintManager.AuthenticationResult?) {
//scanning was successful and has match with one of registered on the device fingerprints
}
override fun onAuthenticationHelp(helpCode: Int, helpString: CharSequence?) {
//case when scanning was failed because of known reason (limit of scan attempts or dirt on the scanner's sensor).