View GetCipherForEncryption.kt
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
override fun getCipherForEncryption(keyName: String): Cipher { | |
val cipher = getCipher() | |
val secretKey = getOrCreateSecretKey(keyName) | |
cipher.init(Cipher.ENCRYPT_MODE, secretKey) | |
return cipher | |
} |
View secretKey.kt
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
private fun getOrCreateSecretKey(keyName: String): SecretKey { | |
// If Secretkey was previously created for that keyName, then grab and return it. | |
try { | |
val keyStore = KeyStore.getInstance(ANDROID_KEYSTORE) | |
try { | |
keyStore.load(null) // Keystore must be loaded before it can be accessed | |
keyStore.getKey(keyName, null)?.let { | |
return it as SecretKey | |
} | |
} catch (ex: Exception) { |
View LoginActivity.kt
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 LoginActivity : AppCompatActivity() { | |
private lateinit var biometricPrompt: BiometricPrompt | |
private lateinit var promptInfo: BiometricPrompt.PromptInfo | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_login) | |
biometricPrompt = createBiometricPrompt() |
View bio_auth.kt
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
val cipher = CryptographyManager().getCipherForEncryption(BIO_KEY_NAME) | |
biometricPrompt.authenticate( | |
buildBiometricPrompt(), | |
BiometricPrompt.CryptoObject(cipher) | |
) |
View bio_authen_status.kt
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
val biometricManager = BiometricManager.from(this) | |
when (biometricManager.canAuthenticate(BIOMETRIC_STRONG)) { | |
BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED, | |
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE, | |
BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE, | |
BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED, | |
-> showErrorNoHardwareBio() | |
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED, | |
BiometricManager.BIOMETRIC_STATUS_UNKNOWN, |
View buildBiometricPrompt.kt
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
private fun buildBiometricPrompt(): BiometricPrompt.PromptInfo { | |
return BiometricPrompt.PromptInfo.Builder() | |
.setTitle(getString(R.string.bio_authen_title)) | |
.setDescription(getString(R.string.bio_authen_description)) | |
.setNegativeButtonText(getString(R.string.bio_authen_negative_button)) | |
.setConfirmationRequired(false) //Allows user to authenticate without performing an action, such as pressing a button, after their biometric credential is accepted. | |
.setAllowedAuthenticators(BIOMETRIC_STRONG) | |
.build() | |
} |
View build.gradle
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
def biometric_version = '1.1.0' | |
//Biometric | |
implementation "androidx.biometric:biometric:$biometric_version" |
View GradientConstant.kt
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
import android.content.Context | |
import android.graphics.drawable.GradientDrawable | |
import androidx.core.content.ContextCompat | |
class GradientConstant { | |
companion object { | |
fun goldGradient(activity: Context): GradientDrawable { | |
val colors: IntArray = intArrayOf( |
View MainActivity.java
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
package com.example.myapplication; | |
import android.graphics.Color; | |
import android.graphics.Typeface; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.text.SpannableString; | |
import android.text.style.ForegroundColorSpan; | |
import android.text.style.RelativeSizeSpan; | |
import android.text.style.StyleSpan; |
View ApiHelper.kt
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
// Retrofit2/OkHttp3 CookieJar Interceptor kotlin | |
// JaoSrikate | |
import android.util.Log | |
import android.webkit.CookieManager | |
import io.reactivex.Observable | |
import okhttp3.* | |
import okhttp3.logging.HttpLoggingInterceptor | |
import retrofit2.Call | |
import retrofit2.Response |