Bladeren bron

Added CryptoAbstraction.GenerateRandom(int length) method.

Gert Driesen 8 jaren geleden
bovenliggende
commit
3e1dd2d345
1 gewijzigde bestanden met toevoegingen van 12 en 0 verwijderingen
  1. 12 0
      src/Renci.SshNet/Abstractions/CryptoAbstraction.cs

+ 12 - 0
src/Renci.SshNet/Abstractions/CryptoAbstraction.cs

@@ -9,6 +9,18 @@ namespace Renci.SshNet.Abstractions
         private static readonly System.Security.Cryptography.RandomNumberGenerator Randomizer = CreateRandomNumberGenerator();
 #endif
 
+        /// <summary>
+        /// Generates a <see cref="Byte"/> array of the specified length, and fills it with a
+        /// cryptographically strong random sequence of values.
+        /// </summary>
+        /// <param name="length">The length of the array generate.</param>
+        public static byte[] GenerateRandom(int length)
+        {
+            var random = new byte[length];
+            GenerateRandom(random);
+            return random;
+        }
+
         /// <summary>
         /// Fills an array of bytes with a cryptographically strong random sequence of values.
         /// </summary>