C# Class StreamCryptor.Cryptor

Class to encrypt and decrypt files with use of stream. Using: libsodium and protobuf-net.
Show file Open project: bitbeans/StreamCryptor

Public Methods

Method Description
DecryptFileWithStream ( Sodium.KeyPair keyPair, string inputFile, string outputFolder, bool overWrite = false ) : string

Decrypts a file with libsodium and protobuf-net.

DecryptFileWithStream ( byte recipientPrivateKey, string inputFile, string outputFolder, bool overWrite = false ) : string

Decrypts a file with libsodium and protobuf-net.

DecryptFileWithStreamAsync ( Sodium.KeyPair keyPair, string inputFile, IProgress decryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Decrypts a file asynchron into memory with libsodium and protobuf-net.

This method can throw an OutOfMemoryException when there is not enough ram to hold the DecryptedFile!

DecryptFileWithStreamAsync ( byte recipientPrivateKey, string inputFile, IProgress decryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Decrypts a file asynchron into memory with libsodium and protobuf-net.

This method can throw an OutOfMemoryException when there is not enough ram to hold the DecryptedFile!

DecryptFileWithStreamAsync ( Sodium.KeyPair keyPair, string inputFile, string outputFolder, IProgress decryptionProgress = null, bool overWrite = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Decrypts a file asynchron with libsodium and protobuf-net.

DecryptFileWithStreamAsync ( byte recipientPrivateKey, string inputFile, string outputFolder, IProgress decryptionProgress = null, bool overWrite = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Decrypts a file asynchron with libsodium and protobuf-net.

This method needs a revision.

DecryptMemoryStreamAsync ( byte recipientPrivateKey, MemoryStream inputStream, IProgress decryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Decrypts a memory stream asynchron into memory with libsodium and protobuf-net.

This method can throw an OutOfMemoryException when there is not enough ram to hold the DecryptedFile!

EncrypMemoryStreamAsync ( byte senderPrivateKey, byte senderPublicKey, byte recipientPublicKey, string filename, MemoryStream inputStream, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, IProgress encryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Encrypts a file asynchron with libsodium and protobuf-net.

EncryptFileWithStream ( Sodium.KeyPair senderKeyPair, byte recipientPublicKey, string inputFile, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false ) : string

Encrypts a file with libsodium and protobuf-net.

The outputFolder is equal to the inputFolder.

EncryptFileWithStream ( Sodium.KeyPair senderKeyPair, string inputFile, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false ) : string

(Self)Encrypts a file with libsodium and protobuf-net.

The outputFolder is equal to the inputFolder.

EncryptFileWithStream ( byte senderPrivateKey, byte senderPublicKey, byte recipientPublicKey, string inputFile, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false ) : string

Encrypts a file with libsodium and protobuf-net.

EncryptFileWithStreamAsync ( Sodium.KeyPair senderKeyPair, byte recipientPublicKey, string inputFile, IProgress encryptionProgress = null, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Encrypts a file asynchron with libsodium and protobuf-net.

The outputFolder is equal to the inputFolder.

EncryptFileWithStreamAsync ( Sodium.KeyPair senderKeyPair, string inputFile, IProgress encryptionProgress = null, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task

(Self)Encrypts a file asynchron with libsodium and protobuf-net.

The outputFolder is equal to the inputFolder.

EncryptFileWithStreamAsync ( byte senderPrivateKey, byte senderPublicKey, byte recipientPublicKey, string inputFile, IProgress encryptionProgress = null, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Encrypts a file asynchron with libsodium and protobuf-net.

Private Methods

Method Description
EncryptFileChunk ( byte unencryptedChunk, int chunkNumber, byte baseNonce, byte ephemeralKey, bool isLast ) : EncryptedFileChunk

Encrypts a file chunk.

GetChunkNonce ( byte baseNonce, int chunkNumber, bool isLastChunkInStream = false ) : byte[]

Generates an accumulated nonce.

ValidateKeyPair ( Sodium.KeyPair keyPair ) : bool

Checks a keypair for the right length.

Method Details

DecryptFileWithStream() public static method

Decrypts a file with libsodium and protobuf-net.
public static DecryptFileWithStream ( Sodium.KeyPair keyPair, string inputFile, string outputFolder, bool overWrite = false ) : string
keyPair Sodium.KeyPair The KeyPair to decrypt the ephemeralKey.
inputFile string An encrypted file.
outputFolder string There the decrypted file will be stored.
overWrite bool Overwrite the output file if it exist.
return string

DecryptFileWithStream() public static method

Decrypts a file with libsodium and protobuf-net.
public static DecryptFileWithStream ( byte recipientPrivateKey, string inputFile, string outputFolder, bool overWrite = false ) : string
recipientPrivateKey byte A 32 byte private key.
inputFile string An encrypted file.
outputFolder string There the decrypted file will be stored.
overWrite bool Overwrite the output file if it exist.
return string

DecryptFileWithStreamAsync() public static method

Decrypts a file asynchron into memory with libsodium and protobuf-net.
This method can throw an OutOfMemoryException when there is not enough ram to hold the DecryptedFile!
public static DecryptFileWithStreamAsync ( Sodium.KeyPair keyPair, string inputFile, IProgress decryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
keyPair Sodium.KeyPair The KeyPair to decrypt the ephemeralKey.
inputFile string An encrypted file.
decryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
cancellationToken CancellationToken Token to request task cancellation.
return Task

DecryptFileWithStreamAsync() public static method

Decrypts a file asynchron into memory with libsodium and protobuf-net.
This method can throw an OutOfMemoryException when there is not enough ram to hold the DecryptedFile!
public static DecryptFileWithStreamAsync ( byte recipientPrivateKey, string inputFile, IProgress decryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
recipientPrivateKey byte A 32 byte private key.
inputFile string An encrypted file.
decryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
cancellationToken CancellationToken Token to request task cancellation.
return Task

DecryptFileWithStreamAsync() public static method

Decrypts a file asynchron with libsodium and protobuf-net.
public static DecryptFileWithStreamAsync ( Sodium.KeyPair keyPair, string inputFile, string outputFolder, IProgress decryptionProgress = null, bool overWrite = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task
keyPair Sodium.KeyPair The KeyPair to decrypt the ephemeralKey.
inputFile string An encrypted file.
outputFolder string There the decrypted file will be stored.
decryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
overWrite bool Overwrite the output file if it exist.
cancellationToken CancellationToken Token to request task cancellation.
return Task

DecryptFileWithStreamAsync() public static method

Decrypts a file asynchron with libsodium and protobuf-net.
This method needs a revision.
public static DecryptFileWithStreamAsync ( byte recipientPrivateKey, string inputFile, string outputFolder, IProgress decryptionProgress = null, bool overWrite = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task
recipientPrivateKey byte A 32 byte private key.
inputFile string An encrypted file.
outputFolder string There the decrypted file will be stored.
decryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
overWrite bool Overwrite the output file if it exist.
cancellationToken CancellationToken Token to request task cancellation.
return Task

DecryptMemoryStreamAsync() public static method

Decrypts a memory stream asynchron into memory with libsodium and protobuf-net.
This method can throw an OutOfMemoryException when there is not enough ram to hold the DecryptedFile!
public static DecryptMemoryStreamAsync ( byte recipientPrivateKey, MemoryStream inputStream, IProgress decryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
recipientPrivateKey byte A 32 byte private key.
inputStream System.IO.MemoryStream An encrypted MemoryStream.
decryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
cancellationToken CancellationToken Token to request task cancellation.
return Task

EncrypMemoryStreamAsync() public static method

Encrypts a file asynchron with libsodium and protobuf-net.
public static EncrypMemoryStreamAsync ( byte senderPrivateKey, byte senderPublicKey, byte recipientPublicKey, string filename, MemoryStream inputStream, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, IProgress encryptionProgress = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
senderPrivateKey byte A 32 byte private key.
senderPublicKey byte A 32 byte public key.
recipientPublicKey byte A 32 byte public key.
filename string The file name.
inputStream System.IO.MemoryStream The input stream.
outputFolder string There the encrypted file will be stored, if this is null the input directory is used.
fileExtension string Set a custom file extenstion: .whatever
maskFileName bool Replaces the filename with some random name.
encryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
cancellationToken CancellationToken Token to request task cancellation.
return Task

EncryptFileWithStream() public static method

Encrypts a file with libsodium and protobuf-net.
The outputFolder is equal to the inputFolder.
public static EncryptFileWithStream ( Sodium.KeyPair senderKeyPair, byte recipientPublicKey, string inputFile, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false ) : string
senderKeyPair Sodium.KeyPair The senders keypair.
recipientPublicKey byte A 32 byte public key.
inputFile string The input file.
outputFolder string There the encrypted file will be stored, if this is null the input directory is used.
fileExtension string Set a custom file extenstion: .whatever
maskFileName bool Replaces the filename with some random name.
return string

EncryptFileWithStream() public static method

(Self)Encrypts a file with libsodium and protobuf-net.
The outputFolder is equal to the inputFolder.
public static EncryptFileWithStream ( Sodium.KeyPair senderKeyPair, string inputFile, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false ) : string
senderKeyPair Sodium.KeyPair The senders keypair.
inputFile string The input file.
outputFolder string There the encrypted file will be stored, if this is null the input directory is used.
fileExtension string Set a custom file extenstion: .whatever
maskFileName bool Replaces the filename with some random name.
return string

EncryptFileWithStream() public static method

Encrypts a file with libsodium and protobuf-net.
public static EncryptFileWithStream ( byte senderPrivateKey, byte senderPublicKey, byte recipientPublicKey, string inputFile, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false ) : string
senderPrivateKey byte A 32 byte private key.
senderPublicKey byte A 32 byte public key.
recipientPublicKey byte A 32 byte public key.
inputFile string The input file.
outputFolder string There the encrypted file will be stored, if this is null the input directory is used.
fileExtension string Set a custom file extenstion: .whatever
maskFileName bool Replaces the filename with some random name.
return string

EncryptFileWithStreamAsync() public static method

Encrypts a file asynchron with libsodium and protobuf-net.
The outputFolder is equal to the inputFolder.
public static EncryptFileWithStreamAsync ( Sodium.KeyPair senderKeyPair, byte recipientPublicKey, string inputFile, IProgress encryptionProgress = null, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task
senderKeyPair Sodium.KeyPair The senders keypair.
recipientPublicKey byte A 32 byte public key.
inputFile string The input file.
encryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
outputFolder string
fileExtension string Set a custom file extenstion: .whatever
maskFileName bool Replaces the filename with some random name.
cancellationToken CancellationToken Token to request task cancellation.
return Task

EncryptFileWithStreamAsync() public static method

(Self)Encrypts a file asynchron with libsodium and protobuf-net.
The outputFolder is equal to the inputFolder.
public static EncryptFileWithStreamAsync ( Sodium.KeyPair senderKeyPair, string inputFile, IProgress encryptionProgress = null, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task
senderKeyPair Sodium.KeyPair The senders keypair.
inputFile string The input file.
encryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
outputFolder string
fileExtension string Set a custom file extenstion: .whatever
maskFileName bool Replaces the filename with some random name.
cancellationToken CancellationToken Token to request task cancellation.
return Task

EncryptFileWithStreamAsync() public static method

Encrypts a file asynchron with libsodium and protobuf-net.
public static EncryptFileWithStreamAsync ( byte senderPrivateKey, byte senderPublicKey, byte recipientPublicKey, string inputFile, IProgress encryptionProgress = null, string outputFolder = null, string fileExtension = DEFAULT_FILE_EXTENSION, bool maskFileName = false, CancellationToken cancellationToken = default(CancellationToken) ) : Task
senderPrivateKey byte A 32 byte private key.
senderPublicKey byte A 32 byte public key.
recipientPublicKey byte A 32 byte public key.
inputFile string The input file.
encryptionProgress IProgress StreamCryptorTaskAsyncProgress object.
outputFolder string There the encrypted file will be stored, if this is null the input directory is used.
fileExtension string Set a custom file extenstion: .whatever
maskFileName bool Replaces the filename with some random name.
cancellationToken CancellationToken Token to request task cancellation.
return Task