Skip to content

duplicati/sharpaescrypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SharpAESCrypt

A C# implementation of the AESCrypt file format.

This .NET AES Crypt package contains the C# class SharpAESCrypt.SharpAESCrypt, which provides file encryption and decryption using the aescrypt file format.

Version 2 of the AES File Format is supported for reading and writing. Versions 0 and 1 are not verified, but there is code to read and write the formats.

Downloads

You can install SharpAESCrypt from NuGet.

The library is targeting .NET8. For versions supporting Mono and .NET4, use v1.3.4 with a different codebase.

Usage

With a reference to SharpAESCrypt, the primary interface are static methods:

    using SharpAESCrypt;
    AESCrypt.Encrypt("password", "inputfile", "outputfile");
    AESCrypt.Decrypt("password", "inputfile", "outputfile");
    AESCrypt.Encrypt("password", inputStream, outputStream);
    AESCrypt.Decrypt("password", inputStream, outputStream);

For uses where a stream is required/prefered, streams can also be created by wrapping either output or input:

    var encStream = new EncryptingStream(password, outputStream);
    var decStream = new DecryptingStream(password, inputStream);

Remember to either call Dispose() or FlushFinalBlock() after using the stream.

Options

Generally, it is recommended that only the default options are applied, but it is possible to toggle some options via the optional options parameter.

For encrypting, you can control the written fileversion and what headers to include (if using v2):

var options = new EncryptionOptions(
    InsertCreatedByIdentifier: true,
    InsertTimeStamp: true,
    InsertPlaceholder: true,
    FileVersion: AESCrypt.DEFAULT_FILE_VERSION,
    LeaveOpen: false,
    AdditionalExtensions = new Dictionary<string, byte[]> {
        { "aes", new byte[] { 0x41, 0x45, 0x53 } }
    }
);

SharpAESCrypt.Encrypt("password", "inputfile", "outputfile", options);

For decrypting you can toggle some compatibility options:

var options = new DecyptionOptions(
    MinVersion: 2,
    LeaveOpen: false,
    IgnorePaddingBytes: false,
    IgnoreFileLength: false
);

SharpAESCrypt.Decrypt("password", "inputfile", "outputfile"), options;

The option IgnorePaddingBytes can be set to true to skip a consistency check made by this library. The consistency check counters a length modification vulnerability in the original format. If you need to read files generated by another tool, you may need to toggle this option.

About

C# Implementation of AESCrypt file format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages