ks-no / fiks-asice-dotnet

Library for creating, reading and validating ASIC-E packages
MIT License
10 stars 7 forks source link
asic asic-e cades-descriptor dotnet-core2 dotnet-core2-2 dotnet-standard

fiks-asice

MIT license Nuget GitHub issues GitHub Release Date

Library for working with ASiC-E packages in .Net Core based projects. This project is created by KS and released under a MIT license.

For more information on how to use this library, check the unit test module. The long term goal of this project is to be functionally compliant with the DIFI ASiC library for Java.

Currently implements:

TODO:

Examples

Create ASiC-E package containing single file

using (var outStream = // create outstream)
using (var fileStream = // open FileStream )
{
    using (var asiceBuilder =
        AsiceBuilder.Create(outStream, MessageDigestAlgorithm.SHA256, signingCertificates))
    {
        asiceBuilder.AddFile(fileStream)

        var asiceArchive = asiceBuilder.Build();
        // archive is created, at this point the data will have been flushed to the outStream
    }
}

Read data from ASiC-E

IAsicReader reader = new AsiceReader();
using (var inputStream = // ASiC-E package to read)
using (var asice = reader.Read(inputStream))
{
    foreach (var asiceReadEntry in asice.Entries)
    {
        using (var entryStream = asiceReadEntry.OpenStream())
        using (var outStream = // stream to output the data to)
        {
            entryStream.CopyTo(bufferStream);
        }
    }

    // Check that all digests declared in the manifest are valid
    if(asice.DigestVerifier.Verification().AllValid) 
    {
        // Do something
    } 
    else
    {
        // Handle error
    }
}