Show / Hide Table of Contents

Class SymmetricCryptography

Service interface implementation for symmetrically encrypting/decrypting data (raw byte[] arrays) using System.Security.Cryptography.AesManaged.

Please keep in mind that the data you encrypt with EncryptWithPassword(byte[], string) can only be decrypted using the same password and the corresponding mirror method DecryptWithPassword(byte[], string).

Likewise, data encrypted using Encrypt(byte[]) can only be decrypted again using Decrypt(EncryptionResult) respectively. Implements the ISymmetricCryptography interface.
Inheritance
object
SymmetricCryptography
Implements
ISymmetricCryptography
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: GlitchedPolygons.Services.Cryptography.Symmetric
Assembly: GlitchedPolygons.Services.Cryptography.Symmetric.dll
Syntax
public class SymmetricCryptography : ISymmetricCryptography

Methods

Decrypt(EncryptionResult)

Decrypts the specified EncryptionResult that was obtained using Encrypt(byte[]).

Declaration
public byte[] Decrypt(EncryptionResult encryptionResult)
Parameters
Type Name Description
EncryptionResult encryptionResult

The EncryptionResult that was obtained using Encrypt(byte[]).

Returns
Type Description
byte[]

Decrypted byte[] array or null if decryption failed.

DecryptAsync(EncryptionResult)

Asynchronously decrypts the specified EncryptionResult that was obtained using EncryptAsync(byte[]).

Declaration
public Task<byte[]> DecryptAsync(EncryptionResult encryptionResult)
Parameters
Type Name Description
EncryptionResult encryptionResult

The EncryptionResult that was obtained using EncryptAsync(byte[]).

Returns
Type Description
Task<byte[]>

Decrypted byte[] or null if decryption failed.

DecryptWithPassword(byte[], string)

Decrypts data that was encrypted using EncryptWithPassword(byte[], string).

Declaration
public byte[] DecryptWithPassword(byte[] encryptedBytes, string password)
Parameters
Type Name Description
byte[] encryptedBytes

The encrypted data.

string password

The password that was used to encrypt the data.

Returns
Type Description
byte[]

The decrypted byte[] array.

DecryptWithPassword(string, string)

Decrypts a string that was encrypted using EncryptWithPassword(string, string).

Declaration
public string DecryptWithPassword(string data, string password)
Parameters
Type Name Description
string data

The encrypted data.

string password

The password that was used to encrypt the data.

Returns
Type Description
string

The decrypted data.

DecryptWithPasswordAsync(byte[], string)

Asynchronously decrypts data that was encrypted using EncryptWithPasswordAsync(byte[], string).

Declaration
public Task<byte[]> DecryptWithPasswordAsync(byte[] encryptedBytes, string password)
Parameters
Type Name Description
byte[] encryptedBytes

The encrypted data.

string password

The password that was used to encrypt the data.

Returns
Type Description
Task<byte[]>

The decrypted byte[] array.

DecryptWithPasswordAsync(string, string)

Asynchronously decrypts a string that was encrypted using EncryptWithPassword(string, string).

Declaration
public Task<string> DecryptWithPasswordAsync(string data, string password)
Parameters
Type Name Description
string data

The encrypted data string.

string password

The password that was used to encrypt the data.

Returns
Type Description
Task<string>

The decrypted string; string.Empty if you passed invalid arguments; null if decryption failed.

Encrypt(byte[])

Encrypts the specified data using a randomly generated key and initialization vector.

Returns an EncryptionResult containing the encrypted byte[] array + the used encryption key and iv.
Declaration
public EncryptionResult Encrypt(byte[] data)
Parameters
Type Name Description
byte[] data

The data to encrypt.

Returns
Type Description
EncryptionResult

EncryptionResult containing the encrypted byte[] array + the used encryption key and iv.

EncryptAsync(byte[])

Encrypts the specified data asynchronously using a randomly generated key and initialization vector.

Returns an EncryptionResult containing the encrypted byte[] array + the used encryption key and iv.
Declaration
public Task<EncryptionResult> EncryptAsync(byte[] data)
Parameters
Type Name Description
byte[] data

The data to encrypt.

Returns
Type Description
Task<EncryptionResult>

EncryptionResult containing the encrypted byte[] array + the used encryption key and iv.

EncryptWithPassword(byte[], string)

Encrypts data using a password.

Declaration
public byte[] EncryptWithPassword(byte[] data, string password)
Parameters
Type Name Description
byte[] data

The data to encrypt.

string password

The password used to derive the AES key.

Returns
Type Description
byte[]

The encrypted data bytes.

EncryptWithPassword(string, string)

Encrypts data using a password.

Declaration
public string EncryptWithPassword(string data, string password)
Parameters
Type Name Description
string data

The data to encrypt.

string password

The password used to derive the AES key.

Returns
Type Description
string

The encrypted data; null if encryption failed; string.Empty if the passed parameters were invalid.

EncryptWithPasswordAsync(byte[], string)

Encrypts data asynchronously using a password.

Declaration
public Task<byte[]> EncryptWithPasswordAsync(byte[] data, string password)
Parameters
Type Name Description
byte[] data

The data to encrypt.

string password

The password used to derive the AES key.

Returns
Type Description
Task<byte[]>

The encrypted data bytes.

EncryptWithPasswordAsync(string, string)

Encrypts data asynchronously using a password.

Declaration
public Task<string> EncryptWithPasswordAsync(string data, string password)
Parameters
Type Name Description
string data

The data to encrypt asynchronously.

string password

The password used to derive the AES key.

Returns
Type Description
Task<string>

The encrypted data.

Implements

ISymmetricCryptography
Back to top Generated by DocFX