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


C# MD5CryptoServiceProvider.HashBlock方法代码示例

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


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

示例1: OpenSSHPassphraseToKey

        private static byte[] OpenSSHPassphraseToKey(SecureString passphrase, byte[] iv, int length) {
            const int HASH_SIZE = 16;
            const int SALT_SIZE = 8;
            var md5 = new MD5CryptoServiceProvider();
            //var pp  = Encoding.UTF8.GetBytes(passphrase);
            var buf = new byte[((length + HASH_SIZE - 1) / HASH_SIZE) * HASH_SIZE];
            var offset = 0;

            while (offset < length) {
                if (offset > 0)
                    md5.TransformBlock(buf, 0, offset, null, 0);
                //md5.TransformBlock(pp, 0, pp.Length, null, 0);
                md5.HashBlock(passphrase, false);
                md5.TransformFinalBlock(iv, 0, SALT_SIZE);
                Buffer.BlockCopy(md5.Hash, 0, buf, offset, HASH_SIZE);
                offset += HASH_SIZE;
                md5.Initialize();
            }
            md5.Clear();

            var key = new byte[length];
            Buffer.BlockCopy(buf, 0, key, 0, length);
            return key;
        }
开发者ID:saleyn,项目名称:nfx.ssh,代码行数:24,代码来源:OpenSSHPrivateKeyLoader.cs


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