< Summary

Information
Class: Renci.SshNet.Abstractions.CryptoAbstraction
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Abstractions\CryptoAbstraction.cs
Line coverage
65%
Covered lines: 45
Uncovered lines: 24
Coverable lines: 69
Total lines: 159
Line coverage: 65.2%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Abstractions\CryptoAbstraction.cs

#LineLine coverage
 1using System;
 2using Renci.SshNet.Security.Cryptography;
 3
 4namespace Renci.SshNet.Abstractions
 5{
 6    internal static class CryptoAbstraction
 7    {
 48        private static readonly System.Security.Cryptography.RandomNumberGenerator Randomizer = CreateRandomNumberGenera
 9
 10        /// <summary>
 11        /// Generates a <see cref="byte"/> array of the specified length, and fills it with a
 12        /// cryptographically strong random sequence of values.
 13        /// </summary>
 14        /// <param name="length">The length of the array generate.</param>
 15        public static byte[] GenerateRandom(int length)
 130416        {
 130417            var random = new byte[length];
 130418            GenerateRandom(random);
 130419            return random;
 130420        }
 21
 22        /// <summary>
 23        /// Fills an array of bytes with a cryptographically strong random sequence of values.
 24        /// </summary>
 25        /// <param name="data">The array to fill with cryptographically strong random bytes.</param>
 26        /// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langword="null"/>.</exception>
 27        /// <remarks>
 28        /// The length of the byte array determines how many random bytes are produced.
 29        /// </remarks>
 30        public static void GenerateRandom(byte[] data)
 6017531        {
 6017532            Randomizer.GetBytes(data);
 6017533        }
 34
 35        public static System.Security.Cryptography.RandomNumberGenerator CreateRandomNumberGenerator()
 536        {
 537            return System.Security.Cryptography.RandomNumberGenerator.Create();
 538        }
 39
 40        public static System.Security.Cryptography.MD5 CreateMD5()
 6141        {
 42#pragma warning disable CA5351 // Do not use broken cryptographic algorithms
 6143            return System.Security.Cryptography.MD5.Create();
 44#pragma warning restore CA5351 // Do not use broken cryptographic algorithms
 6145        }
 46
 47        public static System.Security.Cryptography.SHA1 CreateSHA1()
 8848        {
 49#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
 8850            return System.Security.Cryptography.SHA1.Create();
 51#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
 8852        }
 53
 54        public static System.Security.Cryptography.SHA256 CreateSHA256()
 945155        {
 945156            return System.Security.Cryptography.SHA256.Create();
 945157        }
 58
 59        public static System.Security.Cryptography.SHA384 CreateSHA384()
 2460        {
 2461            return System.Security.Cryptography.SHA384.Create();
 2462        }
 63
 64        public static System.Security.Cryptography.SHA512 CreateSHA512()
 6665        {
 6666            return System.Security.Cryptography.SHA512.Create();
 6667        }
 68
 69#if FEATURE_HASH_RIPEMD160_CREATE || FEATURE_HASH_RIPEMD160_MANAGED
 70        public static System.Security.Cryptography.RIPEMD160 CreateRIPEMD160()
 071        {
 72#if FEATURE_HASH_RIPEMD160_CREATE
 73#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
 074            return System.Security.Cryptography.RIPEMD160.Create();
 75#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
 76#else
 77            return new System.Security.Cryptography.RIPEMD160Managed();
 78#endif
 079        }
 80#else
 81        public static global::SshNet.Security.Cryptography.RIPEMD160 CreateRIPEMD160()
 082        {
 083            return new global::SshNet.Security.Cryptography.RIPEMD160();
 084        }
 85#endif // FEATURE_HASH_RIPEMD160
 86
 87        public static System.Security.Cryptography.HMACMD5 CreateHMACMD5(byte[] key)
 688        {
 89#pragma warning disable CA5351 // Do not use broken cryptographic algorithms
 690            return new System.Security.Cryptography.HMACMD5(key);
 91#pragma warning restore CA5351 // Do not use broken cryptographic algorithms
 692        }
 93
 94        public static HMACMD5 CreateHMACMD5(byte[] key, int hashSize)
 695        {
 96#pragma warning disable CA5351 // Do not use broken cryptographic algorithms
 697            return new HMACMD5(key, hashSize);
 98#pragma warning restore CA5351 // Do not use broken cryptographic algorithms
 699        }
 100
 101        public static System.Security.Cryptography.HMACSHA1 CreateHMACSHA1(byte[] key)
 2366102        {
 103#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
 2366104            return new System.Security.Cryptography.HMACSHA1(key);
 105#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
 2366106        }
 107
 108        public static HMACSHA1 CreateHMACSHA1(byte[] key, int hashSize)
 6109        {
 110#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
 6111            return new HMACSHA1(key, hashSize);
 112#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
 6113        }
 114
 115        public static System.Security.Cryptography.HMACSHA256 CreateHMACSHA256(byte[] key)
 6116        {
 6117            return new System.Security.Cryptography.HMACSHA256(key);
 6118        }
 119
 120        public static HMACSHA256 CreateHMACSHA256(byte[] key, int hashSize)
 0121        {
 0122            return new HMACSHA256(key, hashSize);
 0123        }
 124
 125        public static System.Security.Cryptography.HMACSHA384 CreateHMACSHA384(byte[] key)
 0126        {
 0127            return new System.Security.Cryptography.HMACSHA384(key);
 0128        }
 129
 130        public static HMACSHA384 CreateHMACSHA384(byte[] key, int hashSize)
 0131        {
 0132            return new HMACSHA384(key, hashSize);
 0133        }
 134
 135        public static System.Security.Cryptography.HMACSHA512 CreateHMACSHA512(byte[] key)
 6136        {
 6137            return new System.Security.Cryptography.HMACSHA512(key);
 6138        }
 139
 140        public static HMACSHA512 CreateHMACSHA512(byte[] key, int hashSize)
 0141        {
 0142            return new HMACSHA512(key, hashSize);
 0143        }
 144
 145#if FEATURE_HMAC_RIPEMD160
 146        public static System.Security.Cryptography.HMACRIPEMD160 CreateHMACRIPEMD160(byte[] key)
 0147        {
 148#pragma warning disable CA5350 // Do not use weak cryptographic algorithms
 0149            return new System.Security.Cryptography.HMACRIPEMD160(key);
 150#pragma warning restore CA5350 // Do not use weak cryptographic algorithms
 0151        }
 152#else
 153        public static global::SshNet.Security.Cryptography.HMACRIPEMD160 CreateHMACRIPEMD160(byte[] key)
 0154        {
 0155            return new global::SshNet.Security.Cryptography.HMACRIPEMD160(key);
 0156        }
 157#endif // FEATURE_HMAC_RIPEMD160
 158    }
 159}