public SymmetricKeyGenerationResult GenerateSymmetricKey(int bitSize)
 {
     var res = new SymmetricKeyGenerationResult();
     try
     {
         byte[] key = new byte[bitSize / 8];
         var rng = new RNGCryptoServiceProvider();
         rng.GetBytes(key);
         res.SymmetricKey = BitConverter.ToString(key).Replace("-", string.Empty);
         res.Success = true;
     }
     catch (Exception ex)
     {
         res.ExceptionMessage = ex.Message;
     }
     return res;
 }
Exemplo n.º 2
0
        public SymmetricKeyGenerationResult GenerateSymmetricKey(int bitSize)
        {
            var res = new SymmetricKeyGenerationResult();

            try
            {
                byte[] key = new byte[bitSize / 8];
                var    rng = new RNGCryptoServiceProvider();
                rng.GetBytes(key);
                res.SymmetricKey = BitConverter.ToString(key).Replace("-", string.Empty);
                res.Success      = true;
            }
            catch (Exception ex)
            {
                res.ExceptionMessage = ex.Message;
            }
            return(res);
        }