EncyptedString

Field: MAX_LENGTH

The maximum text length that the class can contain. It is also the upper limit of the SecureString class.


Method: EncryptedString Parse(String)

EncryptedString is the method that takes the value to be stored encrypted, encrypts it after making the controls, and creates the EncryptedString object.

The EncryptedString object holding the given value is returned as encrypted. The returned object is plain (IsPlain). |Parameter Name | Description | |-----|------| |decryptedString|Value to encrypt. Can not be null and can not be longer than MAX_LENGTH. The default value is returned if a value (string.IsNullOrWhiteSpace) is given that is either blank or empty.| Error Type: ArgumentNullException (This error is thrown if the value is set to null.)

Error Type: FormatException (This error is thrown if the value is longer than MAX_LENGTH.)


Method: EncryptedString FromEncrypted(Binary, Binary, String})

It uses the asymmetrically encrypted data to create an EncryptedString object. It is obtained by giving function to decrypt encrypted data and password.

When sensitive data is read from the database, the EncryptedString object is created with this method. Thus, decryption is only postponed as needed. The EncryptedString object holding the encrypted value is returned. The returned object is encrypted (IsEncrypted).

Parameter Name Description
encryptedValue It is the encrypted value. When Decrypt is called, it is directed as if it is for decryptDelegate function.
decryptDelegate Function that is triggered when Decrypt is called. The encryptedValue is taken as the parameter. As a result, the sensitive data must return decrypted.

Error Type: ArgumentNullException (This error is thrown if the decryptDelegate parameter is set to null.)


Property: IsPlain

Indicates that the record is encrypted by symmetric key in memory. Returns true if the object was created with the Parse method or the SecureString field constructor.


Property: IsEncrypted

Indicates that the record is encrypted in memory with an asymmetric key. Returns true if the object was created using the FromEncrypted method.


Property: IsEmpty

Default value. It can be obtained by default(EncrypedString).


Property: EncryptedValue

IsEncrypted returns the encrypted data with the asymmetric key. If not, returns null data.


Constructor(SecureString)

Converts the given value to the EncryptedString object. Creates a plain object (IsPlain).

Parameter Name Description
secureString SecureString object containing sensitive data.

Method: string Decrypt()

It allows the sensitive data to be solved and turned explicitly. This is a costly process, so it needs to be done only when needed. If the object IsEncrypted is slow, then IsPlain is fast.

Example; Let's say the CVV data is kept encrypted. This data will only be needed during spending. In this case, the data can be decrypted and sent to the related system. Or let's say spending service. In this case, if the stored CVV value equals the stored CVV value, it is decrypted before it is compared.

If the value is default (default(EncryptedString)), an empty string is returned.

Returns the decrypted of the Sensitive data


Method: string ToString()

Directly calls the Decrypt method. This method is implemented due to the Parse/ToString pattern when calling internal services. It is recommended to use Decrypt in code in the same way as Decrypt. Returns the decrypted of the Sensitive data


Method: SecureString ToSecureString()

Converts the object to a SecureString object. If IsEncrypted is true, it is first decrypted with the asymmetric key, then converted to the SecureString object with the symmetric key. Otherwise it will return directly to the SecureString object it is already hosting. So if the object IsEncrypted is slow, IsPlain is fast. Returns the SecureString state of the data held by the object.