-
Notifications
You must be signed in to change notification settings - Fork 3
Generating Random Data
Chrono edited this page Dec 27, 2022
·
2 revisions
For detail descriptions on the functionalities on this section of the cryptography binding, kindly refers to official libsodium documentation.
Initial Functions
public static Byte[] GetRandomBytes(int Count)
public static Byte[] GetSeededRandomBytes(long Count, Byte[] Seed,Boolean ClearKey=false)
Example code (1st)
Byte[] RandomByte = SodiumRNG.GetRandomBytes(32);
//All messagebox functions are only available in .Net 5 Winforms or .Net Framework 4.7.2
//In a similar manner, you can also confirm the presence of the data through libsodium helper
MessageBox.Show(new System.Numerics.BigInteger(RandomByte).ToString());
Example code (2nd)
Byte[] RandomByte = new Byte[32];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(RandomByte);
Byte[] SeededRandomByte = new Byte[32];
SeededRandomByte = SodiumRNG.GetSeededRandomBytes(128, RandomByte);
MessageBox.Show(new System.Numerics.BigInteger(SeededRandomByte).ToString());
//or
Byte[] RandomByte = SodiumRNG.GetRandomBytes(32);
Byte[] SeededRandomByte = new Byte[32];
SeededRandomByte = SodiumRNG.GetSeededRandomBytes(128, RandomByte);
MessageBox.Show(new System.Numerics.BigInteger(SeededRandomByte).ToString());
Initial Functions
public static uint GetUniformUpperBoundRandomNumber(uint upperBound)
public static uint GetRandomNumber()
Example code (1st)
uint MyRNGNumber = SodiumRNG.GetUniformUpperBoundRandomNumber(32);
//Assuming after this initial calling, the variable has this value reside within
//1204e35b2cfb78c3e411d4bb43183e6cf62f765e30ba50bc6e5a7a2194159f04
//What this function actually does is get the remainder after dividing by the given number
//within the custom parameter
MessageBox.Show(MyRNGNumber.ToString());
Example code (2nd)
uint MyRNGNumber = SodiumRNG.GetRandomNumber();
MessageBox.Show(MyRNGNumber.ToString());