Я хочу сохранить[code]password[/code] in Android Key-store just confused where it stores actually the password is it in [code]Sharedpreference[/code] or [code]File[/code] this is the code i tried so far [code]import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.biometric.BiometricPrompt import androidx.core.content.ContextCompat import java.security.KeyStore import javax.crypto.Cipher import javax.crypto.KeyGenerator import javax.crypto.SecretKey import javax.crypto.spec.GCMParameterSpec
class MainActivity : AppCompatActivity() {
private val KEY_ALIAS = "my_secure_key"
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)
val keyStore = KeyStore.getInstance("AndroidKeyStore") keyStore.load(null)
val secretKey = if (keyStore.containsAlias(KEY_ALIAS)) { keyStore.getKey(KEY_ALIAS, null) as SecretKey } else { val keyGenerator = KeyGenerator.getInstance( KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore" )
val keyGenParameterSpec = KeyGenParameterSpec.Builder( KEY_ALIAS, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT ) .setBlockModes(KeyProperties.BLOCK_MODE_GCM) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) .setUserAuthenticationRequired(true) // Requires biometric authentication .build()
val promptInfo = BiometricPrompt.PromptInfo.Builder() .setTitle("Authenticate to access credentials") .setSubtitle("Using your biometric") .setDescription("Authenticate using your fingerprint to access your credentials.") .setNegativeButtonText("Cancel") .build()