marsuser
marsuser

Reputation: 145

How to create master key in Tink android

I wanted to use Tink library and able to encrypt and decrypt data but not understanding what is the purpose of master key in its creation and how to create a master key for it.

 private fun getOrGenerateNewKeysetHandle(): KeysetHandle {
        return AndroidKeysetManager.Builder()
            .withSharedPref(activity, EFE_TINK_KEYSET_NAME, null)
            .withKeyTemplate(AeadKeyTemplates.AES256_GCM)
            .withMasterKeyUri("android-keystore://tink_master_key")
            .build().keysetHandle
    }

Here, how should I create tink_master_key?

Upvotes: 1

Views: 1133

Answers (1)

Thai Duong
Thai Duong

Reputation: 199

A master key is a secret key in Android Keystore. Tink protects its keysets by encrypting them with this master key.

You don't have to generate the master key yourself, but Tink would do that if the master key doesn't exist yet.

You can also generate it following Android Keystore documentation or using AndroidKeystoreKmsClient.getOrGenerateNewAeadKey.

Hope that helps, Thai.

Upvotes: 1

Related Questions