Does Java under android have the ability to store encryption keys in a secure way, for example password protected?

Previously generated like this:

final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(4096, new SecureRandom()); final KeyPair key = keyGen.generateKeyPair(); 
  • why can't you use this code now? - Mikhail Vaysman
  • because I need to protect my keys with a password - Nikola Krivosheya
  • misunderstood. You need a secure vault for keys - Nikola Krivosheya

1 answer 1

To store encrypted keys, you can use KeyStore . The key is generated as usual and placed in the repository.

 final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(4096, new SecureRandom()); final KeyPair key = keyGen.generateKeyPair(); SecretKey mySecretKey = key.getPrivate(); KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection("password"); KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(mySecretKey); keyStore.setEntry("MySecretKey", skEntry, protParam);