Class SymmetricEncryptionServiceBase<TAlgorithm>
A symmetric encryption service base.
Inherited Members
Namespace: Kephas.Cryptography
Assembly: Kephas.Core.dll
Syntax
public abstract class SymmetricEncryptionServiceBase<TAlgorithm> : IEncryptionService, ISyncEncryptionService where TAlgorithm : SymmetricAlgorithm
Type Parameters
Name | Description |
---|---|
TAlgorithm | Type of the algorithm. |
Constructors
| Improve this Doc View SourceSymmetricEncryptionServiceBase(Func<IEncryptionContext, TAlgorithm>)
Initializes a new instance of the SymmetricEncryptionServiceBase<TAlgorithm> class.
Declaration
protected SymmetricEncryptionServiceBase(Func<IEncryptionContext, TAlgorithm> algorithmCtor)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IEncryptionContext, TAlgorithm> | algorithmCtor | The algorithm constructor. |
Methods
| Improve this Doc View SourceCreateSymmetricAlgorithm(IEncryptionContext)
Creates the symmetric algorithm.
Declaration
protected virtual TAlgorithm CreateSymmetricAlgorithm(IEncryptionContext encryptionContext)
Parameters
Type | Name | Description |
---|---|---|
IEncryptionContext | encryptionContext | Context for the encryption. |
Returns
Type | Description |
---|---|
TAlgorithm | The new symmetric algorithm. |
Decrypt(Stream, Stream, TAlgorithm, IEncryptionContext)
Decrypts the stream content.
Declaration
protected virtual void Decrypt(Stream input, Stream output, TAlgorithm algorithm, IEncryptionContext encryptionContext)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream. |
System.IO.Stream | output | The output stream. |
TAlgorithm | algorithm | The algorithm. |
IEncryptionContext | encryptionContext | Context for the encryption. |
Decrypt(Stream, Stream, IEncryptionContext)
Decrypts the input stream and writes the decrypted content into the output stream.
Declaration
public void Decrypt(Stream input, Stream output, IEncryptionContext context = null)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream. |
System.IO.Stream | output | The output stream. |
IEncryptionContext | context | The encryption context (optional). |
DecryptAsync(Stream, Stream, TAlgorithm, IEncryptionContext, CancellationToken)
Decrypts the stream content asynchronously.
Declaration
protected virtual Task DecryptAsync(Stream input, Stream output, TAlgorithm algorithm, IEncryptionContext encryptionContext, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream. |
System.IO.Stream | output | The output stream. |
TAlgorithm | algorithm | The algorithm. |
IEncryptionContext | encryptionContext | Context for the encryption. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A Task. |
DecryptAsync(Stream, Stream, IEncryptionContext, CancellationToken)
Decrypts the input stream and writes the decrypted content into the output stream.
Declaration
public Task DecryptAsync(Stream input, Stream output, IEncryptionContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream. |
System.IO.Stream | output | The output stream. |
IEncryptionContext | context | The encryption context (optional). |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | The asynchronous result. |
Encrypt(Stream, Stream, TAlgorithm, IEncryptionContext)
Encrypts the stream content.
Declaration
protected virtual void Encrypt(Stream input, Stream output, TAlgorithm algorithm, IEncryptionContext encryptionContext)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream to encrypt. |
System.IO.Stream | output | The output stream. |
TAlgorithm | algorithm | The algorithm. |
IEncryptionContext | encryptionContext | Context for the encryption. |
Encrypt(Stream, Stream, IEncryptionContext)
Encrypts the input stream and writes the encrypted content into the output stream.
Declaration
public void Encrypt(Stream input, Stream output, IEncryptionContext context = null)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream. |
System.IO.Stream | output | The output stream. |
IEncryptionContext | context | The encryption context (optional). |
EncryptAsync(Stream, Stream, TAlgorithm, IEncryptionContext, CancellationToken)
Encrypts the stream content asynchronously.
Declaration
protected virtual Task EncryptAsync(Stream input, Stream output, TAlgorithm algorithm, IEncryptionContext encryptionContext, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream to encrypt. |
System.IO.Stream | output | The output stream. |
TAlgorithm | algorithm | The algorithm. |
IEncryptionContext | encryptionContext | Context for the encryption. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A Task. |
EncryptAsync(Stream, Stream, IEncryptionContext, CancellationToken)
Encrypts the input stream and writes the encrypted content into the output stream.
Declaration
public Task EncryptAsync(Stream input, Stream output, IEncryptionContext context = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | input | The input stream. |
System.IO.Stream | output | The output stream. |
IEncryptionContext | context | The encryption context (optional). |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | The asynchronous result. |
GenerateKey(IEncryptionContext)
Generates a key.
Declaration
public virtual byte[] GenerateKey(IEncryptionContext encryptionContext = null)
Parameters
Type | Name | Description |
---|---|---|
IEncryptionContext | encryptionContext | Optional. Context for the encryption. |
Returns
Type | Description |
---|---|
System.Byte[] | An array of byte. |
GetKey(IEncryptionContext)
Gets the encryption/decryption key.
Declaration
protected virtual byte[] GetKey(IEncryptionContext encryptionContext)
Parameters
Type | Name | Description |
---|---|---|
IEncryptionContext | encryptionContext | Context for the encryption. |
Returns
Type | Description |
---|---|
System.Byte[] | An array of byte. |
GetKeySize(IEncryptionContext)
Gets the key size.
Declaration
protected virtual int GetKeySize(IEncryptionContext encryptionContext)
Parameters
Type | Name | Description |
---|---|---|
IEncryptionContext | encryptionContext | Context for the encryption. |
Returns
Type | Description |
---|---|
System.Int32 | The key size. |
GetMismatchedKeySizeEncryptionException(SymmetricAlgorithm, Int32)
Gets mismatched key size encryption exception.
Declaration
protected virtual CryptographicException GetMismatchedKeySizeEncryptionException(SymmetricAlgorithm algorithm, int keySize)
Parameters
Type | Name | Description |
---|---|---|
System.Security.Cryptography.SymmetricAlgorithm | algorithm | The algorithm. |
System.Int32 | keySize | Size of the key. |
Returns
Type | Description |
---|---|
System.Security.Cryptography.CryptographicException | The mismatched key size encryption exception. |