pvWay.Crypto.Core 2.0.0

Tiny utilily encrypting/decrypting texts/objects to/from base64 strings with/without limited lifetime (token)

Install-Package pvWay.Crypto.Core -Version 2.0.0
dotnet add package pvWay.Crypto.Core --version 2.0.0
<PackageReference Include="pvWay.Crypto.Core" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add pvWay.Crypto.Core --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: pvWay.Crypto.Core, 2.0.0"
For F# scripts that support #r syntax, copy this into the source code to reference the package.

Crypto Core

Tiny utilily encrypting/decrypting texts/objects to/from base64 strings

Interfaces

This nuGet has only one public class implementing the following interface

ICrypto

using System;
using System.Threading.Tasks;

namespace pvWay.Crypto.Core
{
    public interface ICrypto: IAsyncDisposable, IDisposable
    {
        Task<string> EncryptAsync(string text);
        Task<string> EncryptAsync<T>(T data) where T: class;
        Task<string> EncryptEphemeralAsync(string text, TimeSpan? validity = null);
        Task<string> EncryptEphemeralAsync<T>(T data, TimeSpan? validity = null) where T : class;
        
        Task<string> DecryptAsync(string base64String);
        Task<T> DecryptAsync<T>(string base64String) where T: class;
        Task<T> DecryptEphemeralAsync<T>(string b64Str);
    }
}

Usage

See here after a short Console that use the pool

The code

using System;
using pvWay.Crypto.Core;

namespace CryptoConsole
{
    internal static class Program
    {
        private const string InitializationVectorString = "0123456789ABCDEF";
        private const string KeyString = "123456789 123456789 123456789 12";


        private static void Main(/*string[] args*/)
        {
            var crypto = new Crypto(
                KeyString, 
                InitializationVectorString,
                TimeSpan.FromSeconds(10));

            var b64 = crypto.EncryptAsync("test").Result;
            Console.WriteLine(b64);
            var text = crypto.DecryptAsync(b64).Result;
            Console.WriteLine(text);

            var mc = new MyClass
            {
                TheHeader = "header",
                TheBody = "Body",
                TheFooter = "Footer"
            };

            b64 = crypto.EncryptAsync(mc).Result;
            Console.WriteLine(b64);
            var mcBack = crypto.DecryptAsync<MyClass>(b64).Result;
            Console.WriteLine(mcBack.TheHeader);
            Console.WriteLine(mcBack.TheBody);
            Console.WriteLine(mcBack.TheFooter);

            b64 = crypto.EncryptEphemeralAsync(mc, TimeSpan.FromSeconds(15)).Result;
            mcBack = crypto.DecryptEphemeralAsync<MyClass>(b64).Result;
            Console.WriteLine(mcBack.TheBody + "is still valid");
        }

        private class MyClass
        {
            public string TheHeader { get; set; }
            public string TheBody { get; set; }
            public string TheFooter { get; set; }
        }

    }
}

Happy coding

Crypto Core

Tiny utilily encrypting/decrypting texts/objects to/from base64 strings

Interfaces

This nuGet has only one public class implementing the following interface

ICrypto

using System;
using System.Threading.Tasks;

namespace pvWay.Crypto.Core
{
    public interface ICrypto: IAsyncDisposable, IDisposable
    {
        Task<string> EncryptAsync(string text);
        Task<string> EncryptAsync<T>(T data) where T: class;
        Task<string> EncryptEphemeralAsync(string text, TimeSpan? validity = null);
        Task<string> EncryptEphemeralAsync<T>(T data, TimeSpan? validity = null) where T : class;
        
        Task<string> DecryptAsync(string base64String);
        Task<T> DecryptAsync<T>(string base64String) where T: class;
        Task<T> DecryptEphemeralAsync<T>(string b64Str);
    }
}

Usage

See here after a short Console that use the pool

The code

using System;
using pvWay.Crypto.Core;

namespace CryptoConsole
{
    internal static class Program
    {
        private const string InitializationVectorString = "0123456789ABCDEF";
        private const string KeyString = "123456789 123456789 123456789 12";


        private static void Main(/*string[] args*/)
        {
            var crypto = new Crypto(
                KeyString, 
                InitializationVectorString,
                TimeSpan.FromSeconds(10));

            var b64 = crypto.EncryptAsync("test").Result;
            Console.WriteLine(b64);
            var text = crypto.DecryptAsync(b64).Result;
            Console.WriteLine(text);

            var mc = new MyClass
            {
                TheHeader = "header",
                TheBody = "Body",
                TheFooter = "Footer"
            };

            b64 = crypto.EncryptAsync(mc).Result;
            Console.WriteLine(b64);
            var mcBack = crypto.DecryptAsync<MyClass>(b64).Result;
            Console.WriteLine(mcBack.TheHeader);
            Console.WriteLine(mcBack.TheBody);
            Console.WriteLine(mcBack.TheFooter);

            b64 = crypto.EncryptEphemeralAsync(mc, TimeSpan.FromSeconds(15)).Result;
            mcBack = crypto.DecryptEphemeralAsync<MyClass>(b64).Result;
            Console.WriteLine(mcBack.TheBody + "is still valid");
        }

        private class MyClass
        {
            public string TheHeader { get; set; }
            public string TheBody { get; set; }
            public string TheFooter { get; set; }
        }

    }
}

Happy coding

Release Notes

now supporting limited lifetime

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.0 155 9/27/2020
1.0.0 187 9/27/2020