コード例 #1
0
        private static string GenerateRandomURLSafeString(int length)
        {
            using var rng = new RNGCryptoServiceProvider();
            var bit_count  = length * 6;
            var byte_count = (bit_count + 7) / 8; // rounded up
            var bytes      = new byte[byte_count];

            rng.GetBytes(bytes);
            return(Base64Util.UrlEncode(bytes));
        }
コード例 #2
0
        /// <summary>
        /// Return the paseed verifier and its challenge
        /// </summary>
        /// <param name="verifier">A secure random generated verifier</param>
        /// <returns></returns>
        public static (string verifier, string challenge) GenerateCodes(string verifier)
        {
            Ensure.ArgumentNotNull(verifier, nameof(verifier));

            if (verifier.Length < VERIFY_MIN_LENGTH || verifier.Length > VERIFY_MAX_LENGTH)
            {
                throw new ArgumentException(
                          $"length must be between {VERIFY_MIN_LENGTH} and {VERIFY_MAX_LENGTH}",
                          nameof(verifier)
                          );
            }

            var challenge = Base64Util.UrlEncode(ComputeSHA256(verifier));

            return(verifier, challenge);
        }