static void Main(string[] args) { Write("How big do you want the key (in bytes): "); string size = ReadLine(); byte[] key = Protector.GetRandomKeyOrIV(int.Parse(size)); WriteLine("Key as byte array: "); for (int b = 0; b < key.Length; b++) { Write($"{key[b]:x2} "); if (((b + 1) % 16) == 0) WriteLine(); } WriteLine(); }
static void CheckRandom() { Console.Write("How big do you want the key (in bytes): "); string size = Console.ReadLine(); byte[] key = Protector.GetRandomKeyOrIV(int.Parse(size)); Console.WriteLine($"Key as byte array:"); for (int b = 0; b < key.Length; b++) { Console.Write($"{key[b]:x2} "); if (((b + 1) % 16) == 0) { Console.WriteLine(); } } Console.WriteLine(); }
static void Main(string[] args) { WriteLine("How many bytes long do you want the key to be? "); string size = ReadLine(); byte[] key = Protector.GetRandomKeyOrIV(int.Parse(size)); WriteLine($"The key as a byte array is:"); for (int i = 0; i < key.Length; i++) { // the argument "X2" is a "format string" that tells the ToString() method how it should format the string. // In this case, "x2" indicates the string should be formatted in uppercase Hexadecimal. (x2 for lowercase hexadecimal) // https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings?redirectedfrom=MSDN Write($"{key[i]:X2} "); if (((i + 1) % 16) == 0) { WriteLine(); // 16 to a line } } WriteLine(); WriteLine($"The key as a string is {key.ToString()}"); }
static void Main(string[] args) { Write("How big do you want the key (in bytes): "); string sizeString = ReadLine(); int size; if (int.TryParse(sizeString, out size)) { byte[] key = Protector.GetRandomKeyOrIV(size); WriteLine("Key as byte array:"); for (int b = 0; b < key.Length; b++) { Write($"{key[b]:x2} "); if ((b + 1) % 16 == 0) { WriteLine(); } } } else { WriteLine("Enter a valid key size."); } }