Class Cipher

Definition

Namespace:
Tizen.Security.SecureRepository.Crypto
Assembly:
Tizen.Security.SecureRepository.dll
API Level:
3

This class provides the methods for encrypting and decrypting data.

C#
Copy
public class Cipher
Inheritance
System.Object
Cipher

Constructors

View Source

Cipher(CipherParameters)

A constructor of Cipher that takes the algorithm specific parameters.

Declaration
C#
Copy
public Cipher(CipherParameters parameters)
Parameters
Type Name Description
CipherParameters parameters

The algorithm specific parameters.

API Level: 3

Properties

View Source

Parameters

The algorithm specific parameters.

Declaration
C#
Copy
public CipherParameters Parameters { get; }
Property Value
Type Description
CipherParameters
API Level: 3

Methods

View Source

Decrypt(String, String, Byte[])

Decrypts data using the selected key and the algorithm.

Declaration
C#
Copy
public byte[] Decrypt(string keyAlias, string password, byte[] cipherText)
Parameters
Type Name Description
System.String keyAlias

Alias of the key to be used for decryption.

System.String password

The password used in decrypting a key value. If password of policy is provided in SaveKey(), the same password should be provided.

System.Byte[] cipherText

Data to be decrypted (some algorithms may require additional information embedded in encrypted data.AES GCM is an example).

Returns
Type Description
System.Byte[]

Decrypted data.

Remarks

The key type specified by keyAlias should be compatible with the algorithm specified in Parameters.

Exceptions
Type Condition
System.ArgumentNullException

The keyAlias or cipherText is null.

System.ArgumentException

The mandatory algorithm parameter is missing or invalid. The optional algorithm parameter is invalid.

System.InvalidOperationException

The key-protecting password isn't matched. The key does not exist with the keyAlias.

API Level: 3
View Source

Encrypt(String, String, Byte[])

Encrypts data using selected key and algorithm.

Declaration
C#
Copy
public byte[] Encrypt(string keyAlias, string password, byte[] plainText)
Parameters
Type Name Description
System.String keyAlias

Alias of the key to be used for encryption.

System.String password

The password used in decrypting a key value. If password of policy is provided in SaveKey(), the same password should be provided.

System.Byte[] plainText

Data to be encrypted. In case of the AES algorithm, there are no restrictions on the size of data. For RSA, the size must be smaller or equal to (key_size_in bytes - 42). Example: For 1024 RSA key, the maximum data size is 1024/8 - 42 = 86.

Returns
Type Description
System.Byte[]

Encrypted data.

Remarks

The key type specified by the keyAlias should be compatible with the algorithm specified in Parameters.

Exceptions
Type Condition
System.ArgumentNullException

The keyAlias or plainText is null.

System.ArgumentException

The mandatory algorithm parameter is missing or invalid. The optional algorithm parameter is invalid.

System.InvalidOperationException

The key-protecting password isn't matched. The key does not exist with the keyAlias.

API Level: 3