Langue

KeyGenParameterSpec.Builder.SetRandomizedEncryptionRequired(Boolean) Method

Definition

Sets whether encryption using this key must be sufficiently randomized to produce different ciphertexts for the same plaintext every time.

[Android.Runtime.Register("setRandomizedEncryptionRequired", "(Z)Landroid/security/keystore/KeyGenParameterSpec$Builder;", "", ApiSince=23)]
public Android.Security.Keystore.KeyGenParameterSpec.Builder SetRandomizedEncryptionRequired(bool required);
[<Android.Runtime.Register("setRandomizedEncryptionRequired", "(Z)Landroid/security/keystore/KeyGenParameterSpec$Builder;", "", ApiSince=23)>]
member this.SetRandomizedEncryptionRequired : bool -> Android.Security.Keystore.KeyGenParameterSpec.Builder

Parameters

required
Boolean

Returns

Attributes

Remarks

Sets whether encryption using this key must be sufficiently randomized to produce different ciphertexts for the same plaintext every time. The formal cryptographic property being required is indistinguishability under chosen-plaintext attack (IND-CPA). This property is important because it mitigates several classes of weaknesses due to which ciphertext may leak information about plaintext. For example, if a given plaintext always produces the same ciphertext, an attacker may see the repeated ciphertexts and be able to deduce something about the plaintext.

By default, IND-CPA is required.

When IND-CPA is required, encryption/decryption transformations which do not offer IND-CPA, such as ECB with a symmetric encryption algorithm or RSA encryption/decryption without padding, are prohibited. In block modes which use an IV, such as GCM, CBC, and CTR, caller-provided IVs are rejected when encrypting to ensure that only random IVs are used.

Before disabling this requirement, consider allowing Cipher to generate a random IV by initializing it for encryption without an IV and then querying the IV with Cipher.getIV(). If an IV is non-random, consider changing the design to use a random IV that is provided with the ciphertext to entities that need to decrypt it. If using RSA encryption without padding, consider encryption padding schemes which offer IND-CPA, such as PKCS#1 or OAEP.

Android reference for android.security.keystore.KeyGenParameterSpec.Builder.setRandomizedEncryptionRequired.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to