• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# HashType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中HashType的典型用法代码示例。如果您正苦于以下问题:C# HashType类的具体用法?C# HashType怎么用?C# HashType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HashType类属于命名空间,在下文中一共展示了HashType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetHashForVerification

 internal byte[] GetHashForVerification(HashType hashType, uint index, byte[] scriptPubKey)
 {
     using (MemoryStream ms = new MemoryStream())
     using (BinaryWriter writer = new BinaryWriter(ms))
     {
         writer.Write(Version);
         writer.WriteVarInt(Inputs.Length);
         for (uint i = 0; i < Inputs.Length; i++)
         {
             writer.Write(Inputs[i].PrevHash);
             writer.Write(Inputs[i].PrevIndex);
             if (i == index)
             {
                 writer.WriteVarInt(scriptPubKey.Length);
                 writer.Write(scriptPubKey);
             }
             else
             {
                 writer.WriteVarInt(0);
             }
             writer.Write(uint.MaxValue);
         }
         writer.Write(Outputs);
         writer.Write(LockTime);
         writer.Write((int)hashType);
         writer.Flush();
         return ms.ToArray().Sha256().Sha256();
     }
 }
开发者ID:erikzhang,项目名称:IceWallet,代码行数:29,代码来源:Transaction.cs


示例2: GetHash

 public static string GetHash(string text, HashType hashType)
 {
     HashAlgorithm _algorithm;
     switch (hashType)
     {
         case HashType.MD5:
             _algorithm = MD5.Create();
             break;
         case HashType.SHA1:
             _algorithm = SHA1.Create();
             break;
         case HashType.SHA256:
             _algorithm = SHA256.Create();
             break;
         case HashType.SHA512:
             _algorithm = SHA512.Create();
             break;
         default:
             throw new ArgumentException("Invalid hash type", "hashType");
     }
     byte[] bytes = Encoding.Unicode.GetBytes(text);
     byte[] hash = _algorithm.ComputeHash(bytes);
     string hashString = string.Empty;
     foreach (byte x in hash)
     {
         hashString += String.Format("{0:x2}", x);
     }
     return hashString;
 }
开发者ID:xuanloc,项目名称:Projects,代码行数:29,代码来源:Utils.cs


示例3: GetHash

        public static string GetHash(string text, HashType hashType = HashType.SHA512)
        {
            HashAlgorithm hashAlgorithm = null;

            switch (hashType)
            {
                case HashType.MD5:
                    hashAlgorithm = new MD5CryptoServiceProvider();
                    break;

                case HashType.SHA1:
                    hashAlgorithm = new SHA1Managed();
                    break;

                case HashType.SHA256:
                    hashAlgorithm = new SHA256Managed();
                    break;

                case HashType.SHA512:
                    hashAlgorithm = new SHA512Managed();
                    break;
            }

            return ComputeHash(text, hashAlgorithm);
        }
开发者ID:sbarski,项目名称:transit,代码行数:25,代码来源:HashHelper.cs


示例4: GetHash

        /// <summary>
        /// Get SHA Hash
        /// </summary>
        /// <param name="plainText"></param>
        /// <returns></returns>
        public virtual string GetHash(string plainText, HashType hashType, bool returnHex)
        {
            string hashText = string.Empty;

            switch (hashType)
            {
                case HashType.SHA1:
                    hashText = GetSHA1(plainText, returnHex);
                    break;

                case HashType.SHA256:
                    hashText = GetSHA256(plainText, returnHex);
                    break;

                case HashType.SHA384:
                    hashText = GetSHA384(plainText, returnHex);
                    break;

                case HashType.SHA512:
                    hashText = GetSHA512(plainText, returnHex);
                    break;
            }

            return hashText;
        }
开发者ID:netsouls,项目名称:eCentral,代码行数:30,代码来源:HashService.cs


示例5: GetHash

 /// <summary>Generates the hash of a text.</summary>
 /// <param name="strPlain">The text of which to generate a hash of.</param>
 /// <param name="hshType">The hash function to use.</param>
 /// <returns>The hash as a hexadecimal string.</returns>
 public static string GetHash(string strPlain, HashType hshType)
 {
     string strRet;
     switch (hshType)
     {
         case HashType.MD5:
             strRet = GetMD5(strPlain);
             break;
         case HashType.SHA1:
             strRet = GetSHA1(strPlain);
             break;
         case HashType.SHA256:
             strRet = GetSHA256(strPlain);
             break;
         case HashType.SHA384:
             strRet = GetSHA384(strPlain);
             break;
         case HashType.SHA512:
             strRet = GetSHA512(strPlain);
             break;
         default:
             strRet = "Invalid HashType";
             break;
     }
     return strRet;
 }
开发者ID:rymarrv,项目名称:Compas,代码行数:30,代码来源:CompasHash.cs


示例6: Create

        public static HashAlgorithm Create(HashType hash)
        {
            switch (hash)
            {
                case HashType.CRC32:
                    return CRC32.Create();

                case HashType.MD5:
                    return MD5.Create();

                case HashType.SHA256:
                    return SHA256.Create();

                case HashType.SHA384:
                    return SHA384.Create();

                case HashType.SHA512:
                    return SHA512.Create();

                case HashType.SHA1:
                    return SHA1.Create();

                default:
                    throw new NotSupportedException("not support hash algorithm :" + hash.ToString());
            }
        }
开发者ID:nokia6102,项目名称:jasily.cologler,代码行数:26,代码来源:JasilyHash.cs


示例7: ComputeHash

        /// <summary>
        /// Computes the hash of given text using given hash algorithm
        /// </summary>
        public static string ComputeHash(HashType type, string text)
        {
            // Encode the text into byte array
            var data = (new UTF8Encoding()).GetBytes(text);
            // Create hash provider
            HashAlgorithm algorithm = null;
            switch (type)
            {
                case HashType.Sha1:
                    algorithm = new SHA1Managed();
                    break;

                case HashType.Sha256:
                    algorithm = new SHA1Managed();
                    break;

                case HashType.Sha512:
                    algorithm = new SHA1Managed();
                    break;

                default:
                    algorithm = new MD5CryptoServiceProvider();
                    break;
            }
            // Compute hash value
            var hash = algorithm.ComputeHash(data);
            // Decodes to string
            return Convert.ToBase64String(hash);
        }
开发者ID:BogamSushil,项目名称:OnlineGrocery,代码行数:32,代码来源:CryptoServices.cs


示例8: HashFile

        internal static string HashFile(string IN_FILE, HashType algo)
        {
            byte[] hashBytes = null;

            switch (algo)
            {
                case HashType.MD5:
                    hashBytes = MD5.Create().ComputeHash(new FileStream(IN_FILE, FileMode.Open));
                    break;
                case HashType.SHA1:
                    hashBytes = SHA1.Create().ComputeHash(new FileStream(IN_FILE, FileMode.Open));
                    break;
                case HashType.SHA256:
                    hashBytes = SHA256.Create().ComputeHash(new FileStream(IN_FILE, FileMode.Open));
                    break;
                case HashType.SHA384:
                    hashBytes = SHA384.Create().ComputeHash(new FileStream(IN_FILE, FileMode.Open));
                    break;
                case HashType.SHA512:
                    hashBytes = SHA512.Create().ComputeHash(new FileStream(IN_FILE, FileMode.Open));
                    break;
            }

            return MakeHashString(hashBytes);
        }
开发者ID:xXxTheDarkprogramerxXx,项目名称:AndroidLib-master,代码行数:25,代码来源:Hasher.cs


示例9: AddFile

 public byte[] AddFile(ulong streamId, Stream file, HashType type = HashType.None)
 {
     EnsureMaximumState(ArchiveState.PushingFiles);
     if (_state == ArchiveState.Initial)
     {
         _outputFilter = DoOutputFiltering(_hashedStream);
         _state = ArchiveState.PushingFiles;
     }
     byte[] ret = null;
     _streamIds.Add(streamId);
     _streamSizes.Add(file.Length);
     Stream stream = file;
     HashAlgorithm hash = null;
     if (type != HashType.None)
     {
         hash = Hash.New(type);
         stream = new HashCalculatorInputFilter(stream, hash);
     }
     stream.CopyTo(_outputFilter);
     if (type != HashType.None)
     {
         stream.Dispose();
         hash.FinishHashing();
         ret = hash.Hash;
     }
     AnyFile = true;
     return ret;
 }
开发者ID:Helios-vmg,项目名称:ObsoleteBackupProgram,代码行数:28,代码来源:ArchiveWriter.cs


示例10: GenerateHash

        public string GenerateHash( HashType HashType, string PlainText, string SaltText )
        {
            if (string.IsNullOrEmpty(PlainText)) {
                throw new ArgumentNullException( "PlainText", "Can't hash blank text" );
            }
            byte[] saltBytes = Encoding.UTF8.GetBytes( SaltText );
            if ( string.IsNullOrEmpty( SaltText ) || saltBytes.IsNullOrEmpty() ) {
                throw new ArgumentNullException( "Salt", "Salt can't be blank" );
            }

            byte[] plainTextBytes = Encoding.UTF8.GetBytes( PlainText );

            // Concatinate text and salt bytes
            byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + saltBytes.Length];

            for ( int i = 0; i < plainTextBytes.Length; i++ ) {
                plainTextWithSaltBytes[i] = plainTextBytes[i];
            }
            for ( int i = 0; i < saltBytes.Length; i++ ) {
                plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i];
            }

            HashAlgorithm hashAlgorithm = this.GetAlgorithm( HashType );
            byte[] hashBytes = hashAlgorithm.ComputeHash( plainTextWithSaltBytes );

            string hashValue = Convert.ToBase64String( hashBytes );
            return hashValue;
        }
开发者ID:robrich,项目名称:BetaSigmaPhi,代码行数:28,代码来源:HashHelper.cs


示例11: ProcessSetting

        internal static void ProcessSetting(string arg) {
            switch (arg.ToLower()) {
                case "/?":
                case "-h":
                case "--help":
                    ShowHelp = true;
                    break;
                    
                case "-ff":
                case "--filefirst":
                    FileFirst = true;
                    break;

                case "--md5":
                    HashType = HashType.Md5;
                    break;
                case "--sha1":
                    HashType = HashType.Sha1;
                    break;
                case "--sha256":
                    HashType = HashType.Sha256;
                    break;

                default:
                    if (arg.StartsWith("--") || arg.StartsWith("-") || arg.StartsWith("/"))
                        throw new ApplicationException("Unknown parameter.");
                    FilePath = arg;
                    break;
            }
        }
开发者ID:rmcgrail,项目名称:hash,代码行数:30,代码来源:Program.cs


示例12: GetHashProvider

 public static HashAlgorithm GetHashProvider(HashType type)
 {
     HashAlgorithm hash = null;
     switch (type)
     {
         case HashType.MD5:
             {
                 hash = new MD5CryptoServiceProvider();
                 break;
             }
         case HashType.SHA1:
             {
                 hash = new SHA1CryptoServiceProvider();
                 break;
             }
         case HashType.SHA256:
             {
                 hash = new SHA256CryptoServiceProvider();
                 break;
             }
         case HashType.SHA384:
             {
                 hash = new SHA384CryptoServiceProvider();
                 break;
             }
         case HashType.SHA512:
             {
                 hash = new SHA512CryptoServiceProvider();
                 break;
             }
     }
     return hash;
 }
开发者ID:kLeZ,项目名称:Gecko,代码行数:33,代码来源:MD5SHAHelper.cs


示例13: HashFile

        internal static string HashFile(string filePath, HashType algo)
        {
            string hexStr;

            FileStream fstream = new FileStream(filePath, FileMode.Open);

            switch (algo)
            {
                case HashType.MD5:
                    hexStr = MD5.Create().ComputeHash(fstream).ToHex(true);
                    break;
                case HashType.SHA1:
                    hexStr = SHA1.Create().ComputeHash(fstream).ToHex(true);
                    break;
                case HashType.SHA512:
                    hexStr = SHA512.Create().ComputeHash(fstream).ToHex(true);
                    break;

                default:
                    hexStr = "";
                    break;
            }

            fstream.Close();

            return hexStr;
        }
开发者ID:fashan00,项目名称:SharpUpdate,代码行数:27,代码来源:Hasher.cs


示例14: Compute

        public static string Compute(HashType type, bool format, string data, string salt)
        {
            HashAlgorithm hash;
            string prefix;
            switch (type)
            {
                case HashType.MD5:
                    prefix = "MD5";
                    hash = new MD5Cng();
                    break;
                case HashType.SHA1:
                    prefix = "SHA1";
                    hash = new SHA1Cng();
                    break;
                case HashType.SHA256:
                    prefix = "SHA256";
                    hash = new SHA256Cng();
                    break;
                case HashType.SHA384:
                    prefix = "SHA384";
                    hash = new SHA384Cng();
                    break;
                case HashType.SHA512:
                    prefix = "SHA512";
                    hash = new SHA512Cng();
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(salt+data);
            byte[] hashed = hash.ComputeHash(inputBytes);
            return format ? $"{{{prefix}:{GetHashHex(hashed)}}}" : GetHashHex(hashed);
        }
开发者ID:caesay,项目名称:NearSight,代码行数:34,代码来源:HashHelper.cs


示例15: HashString

        internal static string HashString(string IN_STRING, HashType algo)
        {
            byte[] inStringBytes = null, hashBytes = null;

            inStringBytes = Encoding.ASCII.GetBytes(IN_STRING);

            switch (algo)
            {
                case HashType.MD5:
                    hashBytes = MD5.Create().ComputeHash(inStringBytes);
                    break;
                case HashType.SHA1:
                    hashBytes = SHA1.Create().ComputeHash(inStringBytes);
                    break;
                case HashType.SHA256:
                    hashBytes = SHA256.Create().ComputeHash(inStringBytes);
                    break;
                case HashType.SHA384:
                    hashBytes = SHA384.Create().ComputeHash(inStringBytes);
                    break;
                case HashType.SHA512:
                    hashBytes = SHA512.Create().ComputeHash(inStringBytes);
                    break;
            }

            return MakeHashString(hashBytes);
        }
开发者ID:xXxTheDarkprogramerxXx,项目名称:AndroidLib-master,代码行数:27,代码来源:Hasher.cs


示例16: ComputeHash

        /// <summary>
        /// Generates a hash for the given plain text value and returns a
        /// base64-encoded result. Before the hash is computed, a random salt
        /// is generated and appended to the plain text. This salt is stored at
        /// the end of the hash value, so it can be used later for hash
        /// verification.
        /// </summary>
        /// <param name="plainText">
        /// Plaintext value to be hashed. The function does not check whether
        /// this parameter is null.
        /// </param>
        /// <param name="hashAlgorithm">
        /// Name of the hash algorithm. Allowed values are: "MD5", "SHA1",
        /// "SHA256", "SHA384", and "SHA512" (if any other value is specified
        /// MD5 hashing algorithm will be used). This value is case-insensitive.
        /// </param>
        /// <returns>
        /// Hash value formatted as a base64-encoded string.
        /// </returns>
        public static string ComputeHash(string plainText,
                                         HashType hashType)
        {
            // Convert plain text into a byte array.
            var plainTextBytes = Encoding.UTF8.GetBytes(plainText);

            // Allocate array, which will hold plain text.
            var plainTextWithSaltBytes =
                new byte[plainTextBytes.Length];

            // Copy plain text bytes into resulting array.
            for (int i = 0; i < plainTextBytes.Length; i++)
                plainTextWithSaltBytes[i] = plainTextBytes[i];

            // Because we support multiple hashing algorithms, we must define
            // hash object as a common (abstract) base class. We will specify the
            // actual hashing algorithm class later during object creation.
            HashAlgorithm hash;

            // Initialize appropriate hashing algorithm class.
            switch (hashType.ToString())
            {
                case "SHA1":
                    hash = new SHA1Managed();
                    break;

                case "SHA256":
                    hash = new SHA256Managed();
                    break;

                case "SHA384":
                    hash = new SHA384Managed();
                    break;

                case "SHA512":
                    hash = new SHA512Managed();
                    break;

                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            // Compute hash value of our plain text with appended salt.
            var hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

            // Create array which will hold hash and original salt bytes.
            var hashWithSaltBytes = new byte[hashBytes.Length];

            // Copy hash bytes into resulting array.
            for (int i = 0; i < hashBytes.Length; i++)
                hashWithSaltBytes[i] = hashBytes[i];

            // Convert result into a base64-encoded string.
            string hashValue = Convert.ToBase64String(hashWithSaltBytes);

            // Return the result.
            return hashValue;
        }
开发者ID:dvgamer,项目名称:Touno.Sentinel-II,代码行数:78,代码来源:HashUtil.cs


示例17: CloneableHash

		public CloneableHash(int hash, HashType type, int size) {
			m_Provider = CAPIProvider.Handle;
			m_Type = type;
			m_Size = size;
			m_Disposed = false;
			if (SspiProvider.CryptDuplicateHash(hash, IntPtr.Zero, 0, out  m_Hash) == 0)
				throw new CryptographicException("Couldn't duplicate hash.");
		}
开发者ID:QardenEden,项目名称:Suru,代码行数:8,代码来源:CloneableHash.cs


示例18: QueueItem

 public QueueItem(FileInfo file, string testHash, QueueItemAction requestedAction, HashType type)
 {
     _File = file;
     _Type = type;
     _TestHash = testHash;
     _Action = requestedAction;
     _Results = QueueItemResult.NotTested;
 }
开发者ID:stevenbenner,项目名称:ultrasfv,代码行数:8,代码来源:QueueItem.cs


示例19: CreateHasher

        private static IHashAlgorithm CreateHasher(HashType hashType)
        {
            #if NETSTANDARD || NETFULL || NETCORE
             return new FullHashAlgorithm(hashType);
            #endif

             throw new NotImplementedException();
        }
开发者ID:aloneguid,项目名称:support,代码行数:8,代码来源:Hashing.cs


示例20: Encrypt

 public static string Encrypt(string toEncrypt, HashType hashType, Encoding enc)
 {
     string ret = "";
     byte[] rawBytes = enc.GetBytes(toEncrypt);
     HashAlgorithm hash = GetHashProvider(hashType);
     byte[] result = hash.ComputeHash(rawBytes);
     ret = enc.GetString(result);
     return ret;
 }
开发者ID:kLeZ,项目名称:Gecko,代码行数:9,代码来源:MD5SHAHelper.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# HashedSet类代码示例发布时间:2022-05-24
下一篇:
C# HashTable类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap