Show / Hide Table of Contents

Class ManagedChaCha20Poly1305

Creates a managed instance of the class.

ManagedChaCha20Poly1305 handles encrypting and decrypting files.

Inheritance
System.Object
ManagedChaCha20Poly1305
Namespace: Cloud_ShareSync.Core.Cryptography.FileEncryption
Assembly: Cloud-ShareSync.Core.Cryptography.dll
Syntax
public class ManagedChaCha20Poly1305 : object

Constructors

| Improve this Doc View Source

ManagedChaCha20Poly1305()

Declaration
public ManagedChaCha20Poly1305()
| Improve this Doc View Source

ManagedChaCha20Poly1305(Nullable<ILogger>)

Declaration
public ManagedChaCha20Poly1305(ILogger? log = null)
Parameters
Type Name Description
System.Nullable<ILogger> log

Fields

| Improve this Doc View Source

_log

Declaration
readonly ILogger? _log
Field Value
Type Description
System.Nullable<ILogger>
| Improve this Doc View Source

_source

Declaration
readonly ActivitySource _source
Field Value
Type Description
ActivitySource
| Improve this Doc View Source

MaxValue

The number of bytes to process before changing nonces.

Declaration
public const int MaxValue = null
Field Value
Type Description
System.Int32

Properties

| Improve this Doc View Source

PlatformSupported

Describes ChaCha20Poly1305 platform support status.

See:
Declaration
public static bool PlatformSupported { get; }
Property Value
Type Description
System.Boolean

Methods

| Improve this Doc View Source

AppendFileChunk(FileInfo, Byte[], Int32)

Common method to append data to the end of the outputFile. order == 0 sets otherwise sets .

Declaration
async Task AppendFileChunk(FileInfo outputFile, byte[] data, int order)
Parameters
Type Name Description
FileInfo outputFile
System.Byte[] data
System.Int32 order
Returns
Type Description
Task
| Improve this Doc View Source

Decrypt(ManagedChaCha20Poly1305DecryptionData, FileInfo, FileInfo)

Uses initialized with decryptionData.Key to decrypt cypherTxtFile into plaintextFile.

Declaration
public async Task Decrypt(ManagedChaCha20Poly1305DecryptionData decryptionData, FileInfo cypherTxtFile, FileInfo plaintextFile)
Parameters
Type Name Description
ManagedChaCha20Poly1305DecryptionData decryptionData
FileInfo cypherTxtFile
FileInfo plaintextFile
Returns
Type Description
Task
| Improve this Doc View Source

DecryptFileChunk(ChaCha20Poly1305, Byte[], Byte[], Byte[], FileInfo, FileInfo, Int64, Int32)

Uses chaPoly and the ManagedChaCha20Poly1305DecryptionData (nonce,tag) to decrypt cypherTxt.Length bytes from offset of cypherTxtFile into plaintextFile.

Declaration
async Task DecryptFileChunk(ChaCha20Poly1305 chaPoly, byte[] nonce, byte[] tag, byte[] cypherTxt, FileInfo cypherTxtFile, FileInfo plaintextFile, long offset, int order)
Parameters
Type Name Description
ChaCha20Poly1305 chaPoly
System.Byte[] nonce
System.Byte[] tag
System.Byte[] cypherTxt
FileInfo cypherTxtFile
FileInfo plaintextFile
System.Int64 offset
System.Int32 order
Returns
Type Description
Task
| Improve this Doc View Source

DecryptFileChunkLoop(FileInfo, FileInfo, ChaCha20Poly1305, List<ManagedChaCha20Poly1305DecryptionKeyNote>, Int64, Int32)

Declaration
async Task DecryptFileChunkLoop(FileInfo plaintextFile, FileInfo cypherTxtFile, ChaCha20Poly1305 chaPoly, List<ManagedChaCha20Poly1305DecryptionKeyNote> keyNoteList, long processedBytes = null, int chunkCount = 0)
Parameters
Type Name Description
FileInfo plaintextFile
FileInfo cypherTxtFile
ChaCha20Poly1305 chaPoly
List<ManagedChaCha20Poly1305DecryptionKeyNote> keyNoteList
System.Int64 processedBytes
System.Int32 chunkCount
Returns
Type Description
Task
| Improve this Doc View Source

DecryptFromKeyFile(FileInfo, FileInfo, FileInfo)

Decrypts cypherTxtFile into plaintextFile by deserializing the keyFile and sending it to Decrypt(ManagedChaCha20Poly1305DecryptionData, FileInfo, FileInfo).

Declaration
public async Task DecryptFromKeyFile(FileInfo keyFile, FileInfo cypherTxtFile, FileInfo plaintextFile)
Parameters
Type Name Description
FileInfo keyFile
FileInfo cypherTxtFile
FileInfo plaintextFile
Returns
Type Description
Task
| Improve this Doc View Source

Encrypt(Byte[], FileInfo, FileInfo, Nullable<FileInfo>)

Uses initialized with a key to encrypt plaintextFile into cypherTxtFile. ManagedChaCha20Poly1305DecryptionData is returned.

ManagedChaCha20Poly1305DecryptionData can also optionally be written to a keyFile.
Declaration
public async Task<ManagedChaCha20Poly1305DecryptionData> Encrypt(byte[] key, FileInfo plaintextFile, FileInfo cypherTxtFile, FileInfo? keyFile = null)
Parameters
Type Name Description
System.Byte[] key
FileInfo plaintextFile
FileInfo cypherTxtFile
System.Nullable<FileInfo> keyFile
Returns
Type Description
Task<ManagedChaCha20Poly1305DecryptionData>
| Improve this Doc View Source

EncryptFile(Byte[], FileInfo, FileInfo)

Uses initialized with key to encrypt plaintextFile into cypherTxtFile. DecryptionData is returned.

Declaration
async Task<ManagedChaCha20Poly1305DecryptionData> EncryptFile(byte[] key, FileInfo plaintextFile, FileInfo cypherTxtFile)
Parameters
Type Name Description
System.Byte[] key
FileInfo plaintextFile
FileInfo cypherTxtFile
Returns
Type Description
Task<ManagedChaCha20Poly1305DecryptionData>
| Improve this Doc View Source

EncryptFileChunk(ChaCha20Poly1305, Byte[], Byte[], FileInfo, FileInfo, Int32, Int64)

Uses chaPoly to read a plaintext.Length section of plaintextFile from the offset and encrypt it into cypherTxtFile.

Declaration
async Task<ManagedChaCha20Poly1305DecryptionKeyNote> EncryptFileChunk(ChaCha20Poly1305 chaPoly, byte[] nonce, byte[] plaintext, FileInfo plaintextFile, FileInfo cypherTxtFile, int order, long offset)
Parameters
Type Name Description
ChaCha20Poly1305 chaPoly
System.Byte[] nonce
System.Byte[] plaintext
FileInfo plaintextFile
FileInfo cypherTxtFile
System.Int32 order
System.Int64 offset
Returns
Type Description
Task<ManagedChaCha20Poly1305DecryptionKeyNote>

ManagedChaCha20Poly1305DecryptionKeyNote (nonce, tag, order) for encrypted section.

| Improve this Doc View Source

EncryptFileChunkLoop(FileInfo, FileInfo, ChaCha20Poly1305, List<Byte[]>, List<ManagedChaCha20Poly1305DecryptionKeyNote>, Int64, Int32)

Declaration
async Task EncryptFileChunkLoop(FileInfo plaintextFile, FileInfo cypherTxtFile, ChaCha20Poly1305 chaPoly, List<byte[]> uniqueNonces, List<ManagedChaCha20Poly1305DecryptionKeyNote> keyNoteList, long processedBytes = null, int chunkCount = 0)
Parameters
Type Name Description
FileInfo plaintextFile
FileInfo cypherTxtFile
ChaCha20Poly1305 chaPoly
List<System.Byte[]> uniqueNonces
List<ManagedChaCha20Poly1305DecryptionKeyNote> keyNoteList
System.Int64 processedBytes
System.Int32 chunkCount
Returns
Type Description
Task
| Improve this Doc View Source

EnsureFileExistsAndHasData(FileInfo)

Declaration
static void EnsureFileExistsAndHasData(FileInfo file)
Parameters
Type Name Description
FileInfo file
| Improve this Doc View Source

GetByteArray(Int32, Int32, Int64, Int64)

Declaration
static byte[] GetByteArray(int chunkCount, int nonceCount, long processedBytes, long plaintextFileLength)
Parameters
Type Name Description
System.Int32 chunkCount
System.Int32 nonceCount
System.Int64 processedBytes
System.Int64 plaintextFileLength
Returns
Type Description
System.Byte[]
| Improve this Doc View Source

GetNonce()

Gets an array filled with 12 random bytes.

Declaration
static byte[] GetNonce()
Returns
Type Description
System.Byte[]
| Improve this Doc View Source

GetNonces(Int64)

Gets one random 12 byte array (nonce) per (MaxValue) bytes of file to encrypt.

Declaration
List<byte[]> GetNonces(long dataLength)
Parameters
Type Name Description
System.Int64 dataLength
Returns
Type Description
List<System.Byte[]>
| Improve this Doc View Source

GetUniqueNonce(List<Byte[]>)

Declaration
static void GetUniqueNonce(List<byte[]> nonces)
Parameters
Type Name Description
List<System.Byte[]> nonces
| Improve this Doc View Source

ReadFileChunkFromOffset(FileInfo, Byte[], Int64)

Reads and returns data.Length bytes from inputFile after the offset

Declaration
async Task<byte[]> ReadFileChunkFromOffset(FileInfo inputFile, byte[] data, long offset)
Parameters
Type Name Description
FileInfo inputFile
System.Byte[] data
System.Int64 offset
Returns
Type Description
Task<System.Byte[]>
| Improve this Doc View Source

WriteDecryptionDataToKeyFile(Nullable<FileInfo>, ManagedChaCha20Poly1305DecryptionData)

Declaration
async Task WriteDecryptionDataToKeyFile(FileInfo? keyFile, ManagedChaCha20Poly1305DecryptionData decryptionData)
Parameters
Type Name Description
System.Nullable<FileInfo> keyFile
ManagedChaCha20Poly1305DecryptionData decryptionData
Returns
Type Description
Task
| Improve this Doc View Source

WriteEncryptLogMessages(Boolean, FileInfo, FileInfo, Nullable<FileInfo>)

Declaration
void WriteEncryptLogMessages(bool message1, FileInfo plaintextFile, FileInfo cypherTxtFile, FileInfo? keyFile)
Parameters
Type Name Description
System.Boolean message1
FileInfo plaintextFile
FileInfo cypherTxtFile
System.Nullable<FileInfo> keyFile
  • Improve this Doc
  • View Source
☀
☾
In This Article
Back to top
About Me | Open Source Acknowledgements | Security
☀
☾