alexdmin

task3

Sep 9th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Security.Cryptography;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. namespace task3
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             int BotChoice = keygen.BotChoice();
  16.             Console.WriteLine(BotChoice);
  17.            
  18.             string BotKey = keygen.getkey(BotChoice);
  19.             Console.WriteLine(BotKey);
  20.  
  21.             byte[] bytes = Encoding.ASCII.GetBytes(BotKey);
  22.             string HMAC = keygen.getHMAC(bytes);
  23.             Console.WriteLine(HMAC);
  24.             Console.ReadKey();
  25.  
  26.         }
  27.     }
  28.     public class keygen
  29.     {
  30.         int KeyValue;
  31.         int HMACValue;
  32.  
  33.         public static int BotChoice()
  34.         {
  35.             Random random = new System.Random();
  36.             int KeyValue = random.Next(1, 5);
  37.             return KeyValue;
  38.         }
  39.         public static string getkey(int BotValue)
  40.         {
  41.             System.Security.Cryptography.AesCryptoServiceProvider crypto = new System.Security.Cryptography.AesCryptoServiceProvider();
  42.             crypto.KeySize = 128;
  43.             crypto.BlockSize = 128;
  44.             crypto.GenerateKey();
  45.             byte[] keyGenerated = crypto.Key;
  46.             string Key = Convert.ToBase64String(keyGenerated);
  47.             return Key;
  48.         }
  49.         public static string getHMAC(byte[] a)
  50.         {
  51.             var HMACValue = new HMACSHA256(a);
  52.             var HMACKey = Convert.ToBase64String(HMACValue.Key);
  53.             return HMACKey;
  54.  
  55.         }
  56.        
  57.     }
  58. }
  59.  
Add Comment
Please, Sign In to add comment