Table of Contents

Class Symmetric

Namespace
SunamoShared.Crypting
Assembly
SunamoShared.dll

Symmetric encryption uses a single key to encrypt and decrypt. Both parties (encryptor and decryptor) must share the same secret key.

public class Symmetric
Inheritance
Symmetric
Inherited Members
Extension Methods

Constructors

Symmetric(Provider, bool)

Instantiates a new symmetric encryption object using the specified provider. Automatically generates a random key. If useDefaultInitializationVector is true, uses the default IV; otherwise generates a random IV.

public Symmetric(Symmetric.Provider provider, bool isUsingDefaultInitializationVector)

Parameters

provider Symmetric.Provider

The symmetric encryption provider to use.

isUsingDefaultInitializationVector bool

Whether to use the default initialization vector.

Properties

IntializationVector

Using the default Cipher Block Chaining (CBC) mode, all data blocks are processed using the value derived from the previous block; the first data block has no previous data block to use, so it needs an InitializationVector to feed the first block.

public DataCrypt IntializationVector { get; set; }

Property Value

DataCrypt

Key

The key used to encrypt/decrypt data. Setting it also configures Min, Max and Step byte limits from the algorithm's legal key sizes.

public DataCrypt Key { get; set; }

Property Value

DataCrypt

KeySizeBits

Key size in bits. Uses the default key size for any given provider; if you want to force a specific key size, set this property.

public int KeySizeBits { get; set; }

Property Value

int

KeySizeBytes

Key size in bytes. Uses the default key size for any given provider; if you want to force a specific key size, set this property.

public int KeySizeBytes { get; set; }

Property Value

int

Methods

Decrypt(DataCrypt)

Decrypts the specified data using preset key and preset initialization vector. Key and IV must be set before calling this method.

public DataCrypt Decrypt(DataCrypt encryptedDataCrypt)

Parameters

encryptedDataCrypt DataCrypt

The encrypted data to decrypt.

Returns

DataCrypt

Decrypt(DataCrypt, DataCrypt)

Decrypts the specified data using provided key and preset initialization vector.

public DataCrypt Decrypt(DataCrypt encryptedDataCrypt, DataCrypt key)

Parameters

encryptedDataCrypt DataCrypt

The encrypted data to decrypt.

key DataCrypt

The decryption key to use.

Returns

DataCrypt

Decrypt(Stream)

Decrypts the specified stream using preset key and preset initialization vector.

public DataCrypt Decrypt(Stream encryptedStream)

Parameters

encryptedStream Stream

The encrypted stream to decrypt.

Returns

DataCrypt

Decrypt(Stream, DataCrypt)

Decrypts the specified stream using provided key and preset initialization vector.

public DataCrypt Decrypt(Stream encryptedStream, DataCrypt key)

Parameters

encryptedStream Stream

The encrypted stream to decrypt.

key DataCrypt

The decryption key to use.

Returns

DataCrypt

Encrypt(DataCrypt)

Encrypts the specified DataCrypt using preset key and preset initialization vector.

public DataCrypt Encrypt(DataCrypt dataCrypt)

Parameters

dataCrypt DataCrypt

The data to encrypt.

Returns

DataCrypt

Encrypt(DataCrypt, DataCrypt)

Encrypts the specified DataCrypt using provided key.

public DataCrypt Encrypt(DataCrypt dataCrypt, DataCrypt key)

Parameters

dataCrypt DataCrypt

The data to encrypt.

key DataCrypt

The encryption key to use.

Returns

DataCrypt

Encrypt(Stream)

Encrypts the specified stream to memory using preset key and preset initialization vector.

public DataCrypt Encrypt(Stream stream)

Parameters

stream Stream

The stream to encrypt.

Returns

DataCrypt

Encrypt(Stream, DataCrypt)

Encrypts the stream to memory using specified key.

public DataCrypt Encrypt(Stream stream, DataCrypt key)

Parameters

stream Stream

The stream to encrypt.

key DataCrypt

The encryption key to use.

Returns

DataCrypt

Encrypt(Stream, DataCrypt, DataCrypt)

Encrypts the stream to memory using provided key and provided initialization vector.

public DataCrypt Encrypt(Stream stream, DataCrypt key, DataCrypt initVector)

Parameters

stream Stream

The stream to encrypt.

key DataCrypt

The encryption key to use.

initVector DataCrypt

The initialization vector to use.

Returns

DataCrypt

RandomInitializationVector()

Generates a random Initialization Vector if one was not provided.

public DataCrypt RandomInitializationVector()

Returns

DataCrypt

RandomKey()

Generates a random key if one was not provided.

public DataCrypt RandomKey()

Returns

DataCrypt