Share via


Cipher.Init Method

Definition

Overloads

Init(CipherMode, IKey, IAlgorithmParameterSpec, SecureRandom)

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

Init(CipherMode, IKey, AlgorithmParameters, SecureRandom)

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

Init(CipherMode, IKey, IAlgorithmParameterSpec)

Initializes this cipher with a key and a set of algorithm parameters.

Init(CipherMode, IKey, SecureRandom)

Initializes this cipher with a key and a source of randomness.

Init(CipherMode, IKey, AlgorithmParameters)

Initializes this cipher with a key and a set of algorithm parameters.

Init(CipherMode, Certificate, SecureRandom)

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

Init(CipherMode, IKey)

Initializes this cipher with a key.

Init(CipherMode, Certificate)

Initializes this cipher with the public key from the given certificate.

Init(CipherMode, IKey, IAlgorithmParameterSpec, SecureRandom)

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

[Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;Ljava/security/SecureRandom;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey? key, Java.Security.Spec.IAlgorithmParameterSpec? params, Java.Security.SecureRandom? random);
[<Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;Ljava/security/SecureRandom;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.IKey * Java.Security.Spec.IAlgorithmParameterSpec * Java.Security.SecureRandom -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

key
IKey

the encryption key

params
IAlgorithmParameterSpec

the algorithm parameters

random
SecureRandom

the source of randomness

Attributes

Exceptions

if the specified key can not be used to initialize this cipher instance.

it the specified parameters are inappropriate for this cipher.

if the specified opmode is invalid.

Remarks

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.Key, java.security.spec.AlgorithmParameterSpec, java.security.SecureRandom).

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

Init(CipherMode, IKey, AlgorithmParameters, SecureRandom)

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

[Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/AlgorithmParameters;Ljava/security/SecureRandom;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey? key, Java.Security.AlgorithmParameters? params, Java.Security.SecureRandom? random);
[<Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/AlgorithmParameters;Ljava/security/SecureRandom;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.IKey * Java.Security.AlgorithmParameters * Java.Security.SecureRandom -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

key
IKey

the encryption key

params
AlgorithmParameters

the algorithm parameters

random
SecureRandom

the source of randomness

Attributes

Exceptions

if the specified key can not be used to initialize this cipher instance.

if the specified parameters are inappropriate for this cipher.

if the specified opmode is invalid.

Remarks

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.Key, java.security.AlgorithmParameters, java.security.SecureRandom).

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

Init(CipherMode, IKey, IAlgorithmParameterSpec)

Initializes this cipher with a key and a set of algorithm parameters.

[Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey? key, Java.Security.Spec.IAlgorithmParameterSpec? params);
[<Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.IKey * Java.Security.Spec.IAlgorithmParameterSpec -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

key
IKey

the encryption key

params
IAlgorithmParameterSpec

the algorithm parameters

Attributes

Exceptions

if the specified key can not be used to initialize this cipher instance.

it the specified parameters are inappropriate for this cipher.

Remarks

Initializes this cipher with a key and a set of algorithm parameters.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them using the java.security.SecureRandom implementation of the highest-priority installed provider as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness will be used.)

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.Key, java.security.spec.AlgorithmParameterSpec).

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

Init(CipherMode, IKey, SecureRandom)

Initializes this cipher with a key and a source of randomness.

[Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/SecureRandom;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey? key, Java.Security.SecureRandom? random);
[<Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/SecureRandom;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.IKey * Java.Security.SecureRandom -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

key
IKey

the encryption key

random
SecureRandom

the source of randomness

Attributes

Exceptions

if the specified key can not be used to initialize this cipher instance.

if the specified opmode is invalid.

Remarks

Initializes this cipher with a key and a source of randomness.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidKeyException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.Key, java.security.SecureRandom).

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

Init(CipherMode, IKey, AlgorithmParameters)

Initializes this cipher with a key and a set of algorithm parameters.

[Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/AlgorithmParameters;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey? key, Java.Security.AlgorithmParameters? params);
[<Android.Runtime.Register("init", "(ILjava/security/Key;Ljava/security/AlgorithmParameters;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.IKey * Java.Security.AlgorithmParameters -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

key
IKey

the encryption key

params
AlgorithmParameters

the algorithm parameters

Attributes

Exceptions

if the specified key can not be used to initialize this cipher instance.

it the specified parameters are inappropriate for this cipher.

Remarks

Initializes this cipher with a key and a set of algorithm parameters.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them using the java.security.SecureRandom implementation of the highest-priority installed provider as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness will be used.)

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.Key, java.security.AlgorithmParameters).

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

Init(CipherMode, Certificate, SecureRandom)

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

[Android.Runtime.Register("init", "(ILjava/security/cert/Certificate;Ljava/security/SecureRandom;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.Cert.Certificate? certificate, Java.Security.SecureRandom? random);
[<Android.Runtime.Register("init", "(ILjava/security/cert/Certificate;Ljava/security/SecureRandom;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.Cert.Certificate * Java.Security.SecureRandom -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

certificate
Certificate

the certificate

random
SecureRandom

the source of randomness

Attributes

Exceptions

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

Remarks

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

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If the certificate is of type X.509 and has a key usage extension field marked as critical, and the value of the key usage extension field implies that the public key in the certificate and its corresponding private key are not supposed to be used for the operation represented by the value of opmode, an InvalidKeyException is thrown.

If this cipher requires any algorithm parameters that cannot be derived from the public key in the given certificate, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidKeyException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.cert.Certificate, java.security.SecureRandom).

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

Init(CipherMode, IKey)

Initializes this cipher with a key.

[Android.Runtime.Register("init", "(ILjava/security/Key;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey? key);
[<Android.Runtime.Register("init", "(ILjava/security/Key;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.IKey -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

key
IKey

the key

Attributes

Exceptions

if the specified key can not be used to initialize this cipher instance.

Remarks

Initializes this cipher with a key.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If this cipher requires any algorithm parameters that cannot be derived from the given key, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidKeyException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them using the java.security.SecureRandom implementation of the highest-priority installed provider as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness will be used.)

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.Key).

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

Init(CipherMode, Certificate)

Initializes this cipher with the public key from the given certificate.

[Android.Runtime.Register("init", "(ILjava/security/cert/Certificate;)V", "")]
public void Init (Javax.Crypto.CipherMode opmode, Java.Security.Cert.Certificate? certificate);
[<Android.Runtime.Register("init", "(ILjava/security/cert/Certificate;)V", "")>]
member this.Init : Javax.Crypto.CipherMode * Java.Security.Cert.Certificate -> unit

Parameters

opmode
CipherMode

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE)

certificate
Certificate

the certificate

Attributes

Exceptions

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

Remarks

Initializes this cipher with the public key from the given certificate.

The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of opmode.

If the certificate is of type X.509 and has a key usage extension field marked as critical, and the value of the key usage extension field implies that the public key in the certificate and its corresponding private key are not supposed to be used for the operation represented by the value of opmode, an InvalidKeyException is thrown.

If this cipher requires any algorithm parameters that cannot be derived from the public key in the given certificate, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption or key wrapping, and raise an InvalidKeyException if it is being initialized for decryption or key unwrapping. The generated parameters can be retrieved using #getParameters() getParameters or #getIV() getIV (if the parameter is an IV).

If this cipher requires algorithm parameters that cannot be derived from the input parameters, and there are no reasonable provider-specific default values, initialization will necessarily fail.

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them using the SecureRandom implementation of the highest-priority installed provider as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness will be used.)

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Java documentation for javax.crypto.Cipher.init(int, java.security.cert.Certificate).

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