I am using Google/Tink's Deterministic symmetric key encryption in my project. Like this-
byte[] ciphertext;
Context context = getApplicationContext();
String plainText="Hello World";
try {
DeterministicAeadConfig.register();
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
try {
KeysetHandle keysetHandle = KeysetHandle.generateNew(
KeyTemplates.get("AES256_SIV"));
Log.d("TAG",keysetHandle.toString());
DeterministicAead daead =
keysetHandle.getPrimitive(DeterministicAead.class);
ciphertext = daead.encryptDeterministically(plainText.getBytes(),null);
String c= new String(Base64.getEncoder().encodeToString(ciphertext));
Log.d("TAG",c);
MasterKey mainKey = new MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build();
Log.d("TAG",mainKey.toString());
String filePath = Environment.getExternalStorageDirectory() + "/my_keyset.json";
String masterKeyUri = "android-keystore://_androidx_security_master_key_";
keysetHandle.write(JsonKeysetWriter.withFile(new File(filePath)),
new AndroidKeystoreKmsClient().getAead(masterKeyUri));
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
}
Everything is okay. Now which master key I am creating for Android keyStore, can be deleted/lost if the user reset the phone or any other accident occur (other reasons). Then Tink's keyset(key) will be un-usable. Is there any way to keep backup of master key or create the master key from user input or any other solution?
Note: AWS KMS or GCP KMS isn't a solution for me. As a newcomer in cryptography, any suggestion/advice will be appreciated.