Skip to content

Instantly share code, notes, and snippets.

View dinorahto's full-sized avatar

Dinorah Tovar dinorahto

View GitHub Profile
@dinorahto
dinorahto / authenticator.kt
Created May 1, 2019 17:53
Authenticator and Interceptor for Retrofit
/**
* Created by Dinorah Tovar on 04/04/18.
* Secondary helper interceptor to skip interceptor headers over Data Module
*/
class SupportInterceptor: Interceptor, Authenticator {
/**
* Interceptor class for setting of the headers for every request
*/
@dinorahto
dinorahto / PinEditTextView
Last active August 3, 2022 19:27
Pin view for OTP
/**
* Custom EditText that paints a bottom line and the text or
* a filled circle if it is a password
*/
class PinEntryEditText : AppCompatEditText {
private var mSpace = 24f //24 dp by default, space between the lines
private var mNumChars = 4f
private var mLineSpacing = 8f //8dp by default, height of the text from our lines
sharedPreferences.edit(commit = true) {
putString("Some key", "Some value")
}
// Release Candidate Option
val sharedPreferences = EncryptedSharedPreferences.create(
"FileName",
masterKeyAlias,
context,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
// Alpha Option
// Release Candidate option
val keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC
val masterKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec)
// Alpha option
val masterKeyAvailable = MasterKey
.Builder(application.applicationContext)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
val spec = KeyGenParameterSpec.Builder(
KEY_NAME,
KeyProperties.PURPOSE_ENCRYPT or
KeyProperties.PURPOSE_DECRYPT
).apply {
setBlockModes(KeyProperties.BLOCK_MODE_CBC)
setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
setUserAuthenticationRequired(true)
setUserAuthenticationValidityDurationSeconds(TIMEOUT_SECONDS)
setRandomizedEncryptionRequired(false)
@dinorahto
dinorahto / KeyPairGenerator.kt
Last active July 26, 2020 04:33
KeyPairGenerator.kt
KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore").apply {
val certBuilder = KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT)
.setKeyValidityStart(keyValidityStart)
.setKeyValidityEnd(keyValidityEnd)
.setCertificateSerialNumber(BigInteger.valueOf(1L))
.setCertificateSubject(X500Principal("CN=MyCompany"))
.setUserAuthenticationRequired(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
initialize(
certBuilder
val biometricPromptBuilder = BiometricPrompt.PromptInfo.Builder()
.setTitle("A nice title")
.setSubtitle("A nicer subtitle")
.setNegativeButtonText("Cancel")
.build()
biometricPrompt.authenticate(promptInfo)
var biometricPrompt = BiometricPrompt(this, executor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
// Error
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
// Success
}