title: How to create masterKey after MasterKeys deprecated in Android
body: <p>I am using the following code to store some information encrypted in my app.</p>
  <pre><code>    val masterKey = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
  
      val sharedPreferences = EncryptedSharedPreferences.create(
          &quot;secret_shared_prefs&quot;,
          masterKey,
          this,
          EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
          EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
      )
  </code></pre>
  <p>Since the MasterKeys class deprecated in Android, I should use the MasterKey class and but I cannot figure out what is the right method to get the same mastery defined.</p>
  <p>Could somebody show the exact match with the available MasterKey and MasterKey.Builder classes?</p>
  <p>The below solution worked like this:</p>
  <pre><code>val spec = KeyGenParameterSpec.Builder(
          &quot;_androidx_security_master_key_&quot;,
          KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
      )
          .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
          .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
          .setKeySize(256)
          .build()
  
      val masterKey: MasterKey = MasterKey.Builder(this)
          .setKeyGenParameterSpec(spec)
          .build()
  
      val sharedPreferences = EncryptedSharedPreferences.create(
          this,
          &quot;secret_shared_prefs&quot;,
          masterKey, // masterKey created above
          EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
          EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM);
  </code></pre>