当前位置: 首页>>代码示例>>C#>>正文


C# SHA256Managed.Initialize方法代码示例

本文整理汇总了C#中System.Security.Cryptography.SHA256Managed.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# SHA256Managed.Initialize方法的具体用法?C# SHA256Managed.Initialize怎么用?C# SHA256Managed.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.SHA256Managed的用法示例。


在下文中一共展示了SHA256Managed.Initialize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SHA256

 public static byte[] SHA256(string str)
 {
     SHA256 sha = new SHA256Managed();
     sha.Initialize();
     //return sha.ComputeHash(str.ToByteArray());
     return sha.ComputeHash(Encoding.UTF8.GetBytes(str));
 }
开发者ID:apeape,项目名称:Cheeeeeeeeese,代码行数:7,代码来源:Crypto.cs

示例2: hashString

 public static String hashString(String text)
 {
     SHA256 hasher = new SHA256Managed();
     hasher.Initialize();
     byte[] bytes = Encoding.Unicode.GetBytes(text);
     byte[] hash = hasher.ComputeHash(bytes);
     return BitConverter.ToString(hash).Replace("-", String.Empty);
 }
开发者ID:mt2309,项目名称:Trading-Game,代码行数:8,代码来源:LoginScreen.xaml.cs

示例3: Sha256

 //Shy Ronnie
 private static string Sha256(string s)
 {
     var sh = new SHA256Managed();
     var request = Encoding.UTF8.GetBytes(s);
     sh.Initialize();
     var b4Bbuff = sh.ComputeHash(request, 0, request.Length);
     var b64 = Convert.ToBase64String(b4Bbuff);
     return b64.Substring(0, 43);
 }
开发者ID:GunioRobot,项目名称:Ooyala,代码行数:10,代码来源:OoyalaBacklotApi.cs

示例4: CalculateFingerprintHash

        public static string CalculateFingerprintHash(string fingerprint)
        {
            SHA256Managed sh = new SHA256Managed();
            byte[] request = UTF8Encoding.UTF8.GetBytes(fingerprint);

            sh.Initialize();
            byte[] hash = sh.ComputeHash(request, 0, request.Length);

            return Convert.ToBase64String(hash);
        }
开发者ID:AlexZeitler,项目名称:SharpDevelop-Servers,代码行数:10,代码来源:ExceptionHelpers.cs

示例5: GetHash

        public byte[] GetHash(string password)
        {
            var passwordData = Encoding.Unicode.GetBytes(password);
            var toHashData = new byte[passwordData.Length + PasswordSalt.Length];
            passwordData.CopyTo(toHashData, 0);
            PasswordSalt.CopyTo(toHashData, passwordData.Length);

            var sha1 = new SHA256Managed();
            sha1.Initialize();
            return sha1.ComputeHash(toHashData);
        }
开发者ID:EricLou,项目名称:EricLouchez,代码行数:11,代码来源:AccountService.cs

示例6: GenerateHash

        public static String GenerateHash(String password)
        {
            //WARNING: This code does not reflect best practice.  It is a simplistic implementation designed to introduce the concept of hashing.
            password = "$$$$$" + password + "$#!%^";
            var pwdBytes = Encoding.UTF8.GetBytes(password);

            SHA256 hashAlg = new SHA256Managed();
            hashAlg.Initialize();
            var hashedBytes = hashAlg.ComputeHash(pwdBytes);
            var hash = Convert.ToBase64String(hashedBytes);
            return hash;
        }
开发者ID:rdespoiu,项目名称:ECT330-FinalProject,代码行数:12,代码来源:SecuredPasswordHash.cs

示例7: CreateNew

 public User CreateNew(NewUser model)
 {
     using (var contextAccessor = new WriteContextAccessor())
     {
         SHA256Managed sha = new SHA256Managed();
         sha.Initialize();
         var user = new User
         {
             Name = model.UserName,
             PasswordHash = sha.ComputeHash(Encoding.UTF8.GetBytes(model.Password)).ToHexString()
         };
         contextAccessor.ReadWriteContext.Users.Add(user);
         contextAccessor.ReadWriteContext.SaveChanges();
         return user;
     }
 }
开发者ID:pat333,项目名称:sqlite-winforms-study,代码行数:16,代码来源:UserService.cs

示例8: SHA256HashPassword

        //===============================================================
        // Function: SHA256HashPassword
        //===============================================================
        private string SHA256HashPassword(string password)
        {
            SHA256Managed hashProvider;
            Byte[] passwordBytes;
            //Byte[] hashBytes;

            passwordBytes = System.Text.Encoding.Unicode.GetBytes(password);
            hashProvider = new SHA256Managed();
            hashProvider.Initialize();
            passwordBytes = hashProvider.ComputeHash(passwordBytes);
            string hashedPassword = Convert.ToBase64String(passwordBytes);

            return hashedPassword;
        }
开发者ID:sedogo,项目名称:business-objects,代码行数:17,代码来源:Users.cs

示例9: GetBytes

        public static byte[] GetBytes(byte[] password, byte[] salt, int iterations, int howManyBytes)
        {
            // round up

            uint cBlocks = (uint)((howManyBytes+ HASH_SIZE_IN_BYTES-1)/HASH_SIZE_IN_BYTES);

            // seed for the pseudo-random fcn: salt + block index
            byte[] saltAndIndex = new byte[salt.Length + 4];
            Array.Copy(salt, 0, saltAndIndex, 0, salt.Length);

            byte[] output = new byte[cBlocks*HASH_SIZE_IN_BYTES];
            int outputOffset = 0;

            SHA256Managed innerHash = new SHA256Managed();
            SHA256Managed outerHash = new SHA256Managed();

            // HMAC says the key must be hashed or padded with zeros
            // so it fits into a single block of the hash in use
            if (password.Length > BLOCK_SIZE_IN_BYTES) {
                password = innerHash.ComputeHash(password);
            }
            byte[] key = new byte[BLOCK_SIZE_IN_BYTES];
            Array.Copy(password, 0, key, 0, password.Length);

            byte[] InnerKey = new byte[BLOCK_SIZE_IN_BYTES];
            byte[] OuterKey = new byte[BLOCK_SIZE_IN_BYTES];
            for (int i = 0; i < BLOCK_SIZE_IN_BYTES; ++i) {
                InnerKey[i] = (byte)(key[i] ^ IPAD);
                OuterKey[i] = (byte)(key[i] ^ OPAD);
            }

            // for each block of desired output
            for (int iBlock = 0; iBlock < cBlocks; ++iBlock) {
                // seed HMAC with salt & block index
                _incrementBigEndianIndex(saltAndIndex, salt.Length);
                byte[] U = saltAndIndex;

                for (int i = 0; i < iterations; ++i) {
                    // simple implementation of HMAC-SHA-256
                    innerHash.Initialize();
                    innerHash.TransformBlock(InnerKey, 0,
                        BLOCK_SIZE_IN_BYTES, InnerKey, 0);
                    innerHash.TransformFinalBlock(U, 0, U.Length);

                    byte[] temp = innerHash.Hash;

                    outerHash.Initialize();
                    outerHash.TransformBlock(OuterKey, 0,
                        BLOCK_SIZE_IN_BYTES, OuterKey, 0);
                    outerHash.TransformFinalBlock(temp, 0, temp.Length);

                    U = outerHash.Hash; // U = result of HMAC

                    // xor result into output buffer
                    _xorByteArray(U, 0, HASH_SIZE_IN_BYTES,
                        output, outputOffset);
                }
                outputOffset += HASH_SIZE_IN_BYTES;
            }
            byte[] result = new byte[howManyBytes];
            Array.Copy(output, 0, result, 0, howManyBytes);
            return result;
        }
开发者ID:roman87,项目名称:Dev,代码行数:63,代码来源:Crypto.cs

示例10: GetJWT

        public static string GetJWT(string clientEmail, RSACryptoServiceProvider privateKey, DateTime now) {
            var payload = new {
                scope = scope,
                iss = clientEmail,
                aud = "https://accounts.google.com/o/oauth2/token",
                exp = (int)(now - zeroDate + TimeSpan.FromHours(1)).TotalSeconds,
                iat = (int)(now - zeroDate).TotalSeconds,
                //sub = "[email protected]",
            };

            string serializedPayload = JsonConvert.SerializeObject(payload);

            using (var hashAlg = new SHA256Managed()) {
                hashAlg.Initialize();
                var headerAndPayload = UrlBase64Encode(serializedHeader) + "." + UrlBase64Encode(serializedPayload);
                var headerPayloadBytes = Encoding.ASCII.GetBytes(headerAndPayload);
                var signature = UrlBase64Encode(privateKey.SignData(headerPayloadBytes, hashAlg));
                return headerAndPayload + "." + signature;
            }

        }
开发者ID:mattcrav,项目名称:GDataDB,代码行数:21,代码来源:GDataDBRequestFactory.cs

示例11: HashPassword

 /// <summary>
 /// Encrypts a given string (password) using the SHA1 cryptography algorithm
 /// </summary>
 /// <param name="password">string (passowrd) to encrypt</param>
 /// <returns>Encrypted hash for the supplied string (password)</returns>
 public string HashPassword(string password)
 {
     Byte[] passwordBytes = Encoding.Unicode.GetBytes(password);
     SHA256Managed hashProvider = new SHA256Managed();
     hashProvider.Initialize();
     passwordBytes = hashProvider.ComputeHash(passwordBytes);
     hashProvider.Clear();
     return Convert.ToBase64String(passwordBytes);
 }
开发者ID:robela,项目名称:cats,代码行数:14,代码来源:UserAccountService.cs

示例12: Hash

 //Create a string from the input
 private static string Hash(string url)
 {
     byte[] result;
     SHA256 shaM = new SHA256Managed();
     byte[] ms = new byte[url.Length];
     for (int i = 0; i < url.Length; i++)
     {
         byte b = Convert.ToByte(url[i]);
         ms[i] = (b);
     }
     shaM.Initialize();
     result = shaM.ComputeHash(ms, 0, ms.Length);
     return BitConverter.ToString(result);
 }
开发者ID:adlnet,项目名称:3D-Repository,代码行数:15,代码来源:APIKeyManager.cs


注:本文中的System.Security.Cryptography.SHA256Managed.Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。