ByteDev.Crypto 3.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 3.0.0
dotnet add package ByteDev.Crypto --version 3.0.0
<PackageReference Include="ByteDev.Crypto" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ByteDev.Crypto --version 3.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 crypto 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(new HashPhrase("Password1"));

bool isLoginSuccessful = service.Verify(new HashPhrase("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 crypto 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(new HashPhrase("Password1"));

bool isLoginSuccessful = service.Verify(new HashPhrase("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.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.0.0 102 4/10/2019
2.1.0 92 3/7/2019
2.0.0 102 2/12/2019
1.2.0 117 12/17/2018
1.1.0 162 9/24/2018
1.0.0 150 8/17/2018