ByteDev.Crypto 2.0.0

Provides simple cryptographic related classes for hashing/verifying data, encrypting/decrypting data and creating random data in .NET.

Install-Package ByteDev.Crypto -Version 2.0.0
dotnet add package ByteDev.Crypto --version 2.0.0
paket add ByteDev.Crypto --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ByteDev.Crypto

Provides simple cryptographic related classes for hashing/verifying data, encrypting/decrypting data and creating ramdon data in .NET.

Installation

ByteDev.Crypto has been written as a .NET Standard 2.0 library, so you can consume it from a .NET Core or .NET Framework 4.6.1 (or greater) application.

ByteDev.Crypto is hosted as a package on nuget.org. To install from the Package Manager Console in Visual Studio run:

Install-Package ByteDev.Crypto

Further details can be found on the nuget page.

Code

The repo can be cloned from git bash:

git clone https://github.com/ByteDev/ByteDev.Crypto

Usage

Hashing

Hash some clear text (returned as base 64 string) and verify a guess is equal.

var service = new HashService();

string hash = service.Hash("Password1");

bool isLoginSuccessful = service.Verify("passwordGuess", hash);

Encryption

Encrypt a secret with a key and then decrypt it.

var algo = new RijndaelAlgorithm();

var keyFactory = new EncryptionKeyIvFactory(algo);
var keyIv = keyFactory.Create("Password1", Encoding.UTF8.GetBytes("someSalt"));

var service = new EncryptionService(algo);

byte[] cipher = service.Encrypt("mySecret", keyIv);

string clearText = service.Decrypt(cipher, keyIv);	// clearText == "mySecret"

Random

Generate a random string of a specified length using only the character set specified.

const int length = 5;

using (var r = new CryptoRandom(CharacterSets.Digits))
{
    string randomString = r.GenerateString(length);
}

ByteDev.Crypto

Provides simple cryptographic related classes for hashing/verifying data, encrypting/decrypting data and creating ramdon data in .NET.

Installation

ByteDev.Crypto has been written as a .NET Standard 2.0 library, so you can consume it from a .NET Core or .NET Framework 4.6.1 (or greater) application.

ByteDev.Crypto is hosted as a package on nuget.org. To install from the Package Manager Console in Visual Studio run:

Install-Package ByteDev.Crypto

Further details can be found on the nuget page.

Code

The repo can be cloned from git bash:

git clone https://github.com/ByteDev/ByteDev.Crypto

Usage

Hashing

Hash some clear text (returned as base 64 string) and verify a guess is equal.

var service = new HashService();

string hash = service.Hash("Password1");

bool isLoginSuccessful = service.Verify("passwordGuess", hash);

Encryption

Encrypt a secret with a key and then decrypt it.

var algo = new RijndaelAlgorithm();

var keyFactory = new EncryptionKeyIvFactory(algo);
var keyIv = keyFactory.Create("Password1", Encoding.UTF8.GetBytes("someSalt"));

var service = new EncryptionService(algo);

byte[] cipher = service.Encrypt("mySecret", keyIv);

string clearText = service.Decrypt(cipher, keyIv);	// clearText == "mySecret"

Random

Generate a random string of a specified length using only the character set specified.

const int length = 5;

using (var r = new CryptoRandom(CharacterSets.Digits))
{
    string randomString = r.GenerateString(length);
}

  • .NETStandard 2.0

    • No dependencies.

Version History

Version Downloads Last updated
2.0.0 26 2/12/2019
1.2.0 67 12/17/2018
1.1.0 105 9/24/2018
1.0.0 95 8/17/2018