Skip to content

TimothyMeadows/SecureRandom.NetCore

Repository files navigation

SecureRandom.NetCore

License: MIT nuget

Implementation of a cryptographic pseudorandom number generator (CPRNG) using Blake2b. Optimized for PinnedMemory.

Install

From a command prompt

dotnet add package SecureRandom.NetCore
Install-Package SecureRandom.NetCore

You can also search for the package via your nuget ui / website:

https://www.nuget.org/packages/SecureRandom.NetCore/

Examples

You can find more examples in the github examples project.

using var cprng = new SecureRandom();

var randomBytes = cprng.NextBytes(16); // create by length

var nextRandomBytes = new byte[32];
cprng.NextBytes(nextRandomBytes); // popualte by size

Constructor

WARNING: Never set seed to false unless you know what your doing. See example in github for more details.

SecureRandom(int rounds = 10, bool seed = true)

Methods

Get the hash output length used when seeding.

int GetSeedLength()

Will add bytes to existing seed material, this will be hashed with blake2b.

void SetSeed(byte[] seed)

Will add number to existing seed material, this will be hashed with blake2b.

void SetSeed(long seed)

Will return a random number between 0, and int.MaxValue.

int Next()

Will return a random number between 0, and maxValue.

int Next(int maxValue)

Will return a random number between minValue, and maxValue.

int Next(int minValue, int maxValue)

Will return random bytes at length.

byte[] NextBytes(int length)

Will populate random bytes by size.

void NextBytes(byte[] bytes)

Will populate random bytes with offset at length.

void NextBytes(byte[] bytes, int offset, int length)

Will return a random double between double.MinValue, and double.MaxValue.

double NextDouble()

Will return a random int between int.MinValue, and int.MaxValue.

int NextInt()

Will return a random long between long.MinValue, and long.MaxValue.

int NextLong()

Will free state, and all seed material.

void Dispose()

About

Cryptographic pseudorandom number generator (CPRNG) using Blake2b, and PinnedMemory.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages