コード例 #1
0
        public void Provide(IBundleVersionProviderContext context)
        {
            byte[] hash;
            using (var sha256 = CryptographyAlgorithms.CreateSHA256())
                hash = sha256.ComputeHash(context.Content);

            context.Result = WebEncoders.Base64UrlEncode(hash);
        }
コード例 #2
0
 private static string GetHashForFile(IFileInfo fileInfo)
 {
     using (var sha256 = CryptographyAlgorithms.CreateSHA256()) {
         using (var readStream = fileInfo.CreateReadStream()) {
             var hash = sha256.ComputeHash(readStream);
             return(WebEncoders.Base64UrlEncode(hash));
         }
     }
 }
コード例 #3
0
        private static string GenerateCookieSuffix(string applicationId)
        {
            using (var sha256 = CryptographyAlgorithms.CreateSHA256())
            {
                var hash    = sha256.ComputeHash(Encoding.UTF8.GetBytes(applicationId));
                var subHash = hash.Take(8).ToArray();

                return(WebEncoders.Base64UrlEncode(subHash));
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a hashed value of the key.
        /// </summary>
        /// <returns>A cryptographic hash of the key.</returns>
        public string GenerateHashedKey()
        {
            var key = GenerateKey();

            // The key is typically too long to be useful, so we use a cryptographic hash
            // as the actual key (better randomization and key distribution, so small vary
            // values will generate dramatically different keys).
            using (var sha256 = CryptographyAlgorithms.CreateSHA256())
            {
                var contentBytes = Encoding.UTF8.GetBytes(key);
                var hashedBytes  = sha256.ComputeHash(contentBytes);
                return(Convert.ToBase64String(hashedBytes));
            }
        }