Android Guides | Samples

Javax.Crypto.Cipher.Init Method

Initializes this cipher instance with the public key from the specified certificate and a source of randomness.

Syntax

[Android.Runtime.Register("init", "(ILjava/security/cert/Certificate;Ljava/security/SecureRandom;)V", "")]
public Void Init ([Android.Runtime.GeneratedEnum] CipherMode opmode, Certificate certificate, SecureRandom random)

Parameters

opmode
the operation this cipher instance should be initialized for (one of: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE).
certificate
the certificate.
random
the source of randomness to be used.

Exceptions

TypeReason
InvalidKeyExceptionif the public key in the certificate can not be used to initialize this cipher instance.

Remarks

Initializes this cipher instance with the public key from the specified certificate and a source of randomness.

The cipher will be initialized for the specified operation (one of: encryption, decryption, key wrapping or key unwrapping) depending on opmode.

It the type of the certificate is X.509 and the certificate has a key usage extension field marked as critical, the specified opmode has the be enabled for this key, otherwise an InvalidKeyException is thrown.

If this cipher instance needs any algorithm parameters that the key in the certificate can not provide, the underlying implementation of this cipher is supposed to generate the required parameters (using its provider or random values). Random values are generated using random.

When a cipher instance is initialized by a call to any of the init methods, the state of the instance is overridden, means it is equivalent to creating a new instance and calling it init method.

[Android Documentation]

Requirements

Namespace: Javax.Crypto
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1