Exemplo n.º 1
0
        public string CalculateHash(string plainText)
        {
            Expect.ArgumentNotNull(plainText, nameof(plainText));
            Expect.ArgumentSatisfies(plainText, x => x.Length > 0, "Length must be > 0.", nameof(plainText));

            return(CalculateHashInternal(plainText));
        }
Exemplo n.º 2
0
        /// <exception cref="ArgumentException"><paramref name="length" /> must be > 0.</exception>
        public static string Generate(int length)
        {
            Expect.ArgumentSatisfies(length, x => x > 0, "Value must be > 0.", nameof(length));

            var randomString = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Trim();

            return(length <= randomString.Length ? randomString.Substring(0, length) : randomString);
        }
Exemplo n.º 3
0
        /// <exception cref="System.ArgumentException"><paramref name="length" /> must be > 0.</exception>
        /// <exception cref="CryptographicException">
        /// The cryptographic service provider (CSP) cannot be acquired.
        /// </exception>
        public static string GenerateSalt(int length)
        {
            Expect.ArgumentSatisfies(length, x => x > 0, "Value must be > 0.", nameof(length));

            var cryptoService = new RNGCryptoServiceProvider();
            var saltBytes     = new byte[length];

            cryptoService.GetNonZeroBytes(saltBytes);
            return(Encoding.Unicode.GetString(saltBytes));
        }