Advertisement
fortsoft

Hash

Feb 2nd, 2021 (edited)
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.36 KB | Source Code | 0 0
  1. /**
  2.  * This is open-source software licensed under the terms of the MIT License.
  3.  *
  4.  * Copyright (c) 2012-2023 Petr Červinka - FortSoft <[email protected]>
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  7.  * of this software and associated documentation files (the "Software"), to deal
  8.  * in the Software without restriction, including without limitation the rights
  9.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.  * copies of the Software, and to permit persons to whom the Software is
  11.  * furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included in all
  14.  * copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  * SOFTWARE.
  23.  **
  24.  * Version 1.1.0.0
  25.  */
  26.  
  27. using System.IO;
  28. using System.Security.Cryptography;
  29. using System.Text;
  30. using System.Text.RegularExpressions;
  31.  
  32. namespace FortSoft.Tools {
  33.  
  34.     /// <summary>
  35.     /// Contains static methods needed to work with hash operations.
  36.     /// </summary>
  37.     public static class Hash {
  38.  
  39.         /// <summary>
  40.         /// Checks if the provided string matches the hash of the appropriate
  41.         /// algorithm.
  42.         /// </summary>
  43.         /// <param name="str">Input string.</param>
  44.         /// <param name="algorithm">Hash algorithm.</param>
  45.         public static bool IsHash(string str, Algorithm algorithm) {
  46.             switch (algorithm) {
  47.                 case Algorithm.MD5:
  48.                     return Regex.IsMatch(str, "^[0-9a-f]{32}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
  49.                 case Algorithm.SHA1:
  50.                     return Regex.IsMatch(str, "^[0-9a-f]{40}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
  51.                 case Algorithm.SHA256:
  52.                     return Regex.IsMatch(str, "^[0-9a-f]{64}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
  53.                 case Algorithm.SHA384:
  54.                     return Regex.IsMatch(str, "^[0-9a-f]{96}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
  55.                 case Algorithm.SHA512:
  56.                     return Regex.IsMatch(str, "^[0-9a-f]{128}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
  57.                 default:
  58.                     return false;
  59.             }
  60.         }
  61.  
  62.         /// <summary>
  63.         /// Checks if the provided string matches the hash of a known algorithm
  64.         /// within this class.
  65.         /// </summary>
  66.         /// <param name="hash">Input hash.</param>
  67.         public static Algorithm GetAlgorithm(string hash) {
  68.             switch (hash.Length) {
  69.                 case 32:
  70.                     return Regex.IsMatch(hash, "^[0-9a-f]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)
  71.                         ? Algorithm.MD5
  72.                         : Algorithm.Undefined;
  73.                 case 40:
  74.                     return Regex.IsMatch(hash, "^[0-9a-f]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)
  75.                         ? Algorithm.SHA1
  76.                         : Algorithm.Undefined;
  77.                 case 64:
  78.                     return Regex.IsMatch(hash, "^[0-9a-f]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)
  79.                         ? Algorithm.SHA256
  80.                         : Algorithm.Undefined;
  81.                 case 96:
  82.                     return Regex.IsMatch(hash, "^[0-9a-f]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)
  83.                         ? Algorithm.SHA384
  84.                         : Algorithm.Undefined;
  85.                 case 128:
  86.                     return Regex.IsMatch(hash, "^[0-9a-f]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)
  87.                         ? Algorithm.SHA512
  88.                         : Algorithm.Undefined;
  89.                 default:
  90.                     return Algorithm.Undefined;
  91.             }
  92.         }
  93.  
  94.         /// <summary>
  95.         /// Converts an array of bytes to a string of sequences of hexadecimal
  96.         /// values.
  97.         /// </summary>
  98.         /// <param name="bytes">Input array of bytes.</param>
  99.         private static string ToHexString(byte[] bytes) {
  100.             StringBuilder stringBuilder = new StringBuilder();
  101.             foreach (byte b in bytes) {
  102.                 stringBuilder.Append(b.ToString("x2"));
  103.             }
  104.             return stringBuilder.ToString();
  105.         }
  106.  
  107.         /// <summary>
  108.         /// Calculates hash using the MD5 message-digest algorithm.
  109.         /// </summary>
  110.         /// <param name="str">Input string.</param>
  111.         /// <param name="encoding">Encoding the text in the string.</param>
  112.         public static string MD5(string str, Encoding encoding) {
  113.             MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
  114.             return ToHexString(md5.ComputeHash(encoding.GetBytes(str)));
  115.         }
  116.  
  117.         /// <summary>
  118.         /// Calculates hash using the SHA-1 (Secure Hash Algorithm 1).
  119.         /// </summary>
  120.         /// <param name="str">Input string.</param>
  121.         /// <param name="encoding">Encoding the text in the string.</param>
  122.         public static string SHA1(string str, Encoding encoding) {
  123.             SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
  124.             return ToHexString(sha1.ComputeHash(encoding.GetBytes(str)));
  125.         }
  126.  
  127.         /// <summary>
  128.         /// Calculates hash using the 256bits SHA-2 (Secure Hash Algorithm 2).
  129.         /// </summary>
  130.         /// <param name="str">Input string.</param>
  131.         /// <param name="encoding">Encoding the text in the string.</param>
  132.         public static string SHA256(string str, Encoding encoding) {
  133.             SHA1CryptoServiceProvider sha256 = new SHA1CryptoServiceProvider();
  134.             return ToHexString(sha256.ComputeHash(encoding.GetBytes(str)));
  135.         }
  136.  
  137.         /// <summary>
  138.         /// Calculates hash using the 384bits SHA-2 (Secure Hash Algorithm 2).
  139.         /// </summary>
  140.         /// <param name="str">Input string.</param>
  141.         /// <param name="encoding">Encoding the text in the string.</param>
  142.         public static string SHA384(string str, Encoding encoding) {
  143.             SHA1CryptoServiceProvider sha384 = new SHA1CryptoServiceProvider();
  144.             return ToHexString(sha384.ComputeHash(encoding.GetBytes(str)));
  145.         }
  146.  
  147.         /// <summary>
  148.         /// Calculates hash using the 512bits SHA-2 (Secure Hash Algorithm 2).
  149.         /// </summary>
  150.         /// <param name="str">Input string.</param>
  151.         /// <param name="encoding">Encoding the text in the string.</param>
  152.         public static string SHA512(string str, Encoding encoding) {
  153.             SHA1CryptoServiceProvider sha512 = new SHA1CryptoServiceProvider();
  154.             return ToHexString(sha512.ComputeHash(encoding.GetBytes(str)));
  155.         }
  156.  
  157.         /// <summary>
  158.         /// Calculates hash using the MD5 message-digest algorithm.
  159.         /// </summary>
  160.         /// <param name="stream">Input stream.</param>
  161.         public static string MD5(Stream stream) {
  162.             MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
  163.             return ToHexString(md5.ComputeHash(stream));
  164.         }
  165.  
  166.         /// <summary>
  167.         /// Calculates hash using the SHA-1 (Secure Hash Algorithm 1).
  168.         /// </summary>
  169.         /// <param name="stream">Input stream.</param>
  170.         public static string SHA1(Stream stream) {
  171.             SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
  172.             return ToHexString(sha1.ComputeHash(stream));
  173.         }
  174.  
  175.         /// <summary>
  176.         /// Calculates hash using the 256bits SHA-2 (Secure Hash Algorithm 2).
  177.         /// </summary>
  178.         /// <param name="stream">Input stream.</param>
  179.         public static string SHA256(Stream stream) {
  180.             SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
  181.             return ToHexString(sha256.ComputeHash(stream));
  182.         }
  183.  
  184.         /// <summary>
  185.         /// Calculates hash using the 384bits SHA-2 (Secure Hash Algorithm 2).
  186.         /// </summary>
  187.         /// <param name="stream">Input stream.</param>
  188.         public static string SHA384(Stream stream) {
  189.             SHA384CryptoServiceProvider sha384 = new SHA384CryptoServiceProvider();
  190.             return ToHexString(sha384.ComputeHash(stream));
  191.         }
  192.  
  193.         /// <summary>
  194.         /// Calculates hash using the 512bits SHA-2 (Secure Hash Algorithm 2).
  195.         /// </summary>
  196.         /// <param name="stream">Input stream.</param>
  197.         public static string SHA512(Stream stream) {
  198.             SHA512CryptoServiceProvider sha512 = new SHA512CryptoServiceProvider();
  199.             return ToHexString(sha512.ComputeHash(stream));
  200.         }
  201.  
  202.         /// <summary>
  203.         /// Calculates hash using the MD5 message-digest algorithm.
  204.         /// </summary>
  205.         /// <param name="filePath">File path.</param>
  206.         public static string MD5(string filePath) {
  207.             using (FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  208.                 MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
  209.                 if (new FileInfo(filePath).Length >= 8192) {
  210.                     byte[] buffer = new byte[8192];
  211.                     int read;
  212.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  213.                         md5.TransformBlock(buffer, 0, read, buffer, 0);
  214.                     }
  215.                     md5.TransformFinalBlock(buffer, 0, 0);
  216.                     return ToHexString(md5.Hash);
  217.                 } else {
  218.                     return ToHexString(md5.ComputeHash(fileStream));
  219.                 }
  220.             }
  221.         }
  222.  
  223.         /// <summary>
  224.         /// Calculates hash using the SHA-1 (Secure Hash Algorithm 1).
  225.         /// </summary>
  226.         /// <param name="filePath">File path.</param>
  227.         public static string SHA1(string filePath) {
  228.             using (FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  229.                 SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
  230.                 if (new FileInfo(filePath).Length >= 8192) {
  231.                     byte[] buffer = new byte[8192];
  232.                     int read;
  233.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  234.                         sha1.TransformBlock(buffer, 0, read, buffer, 0);
  235.                     }
  236.                     sha1.TransformFinalBlock(buffer, 0, 0);
  237.                     return ToHexString(sha1.Hash);
  238.                 } else {
  239.                     return ToHexString(sha1.ComputeHash(fileStream));
  240.                 }
  241.             }
  242.         }
  243.  
  244.         /// <summary>
  245.         /// Calculates hash using the 256bits SHA-2 (Secure Hash Algorithm 2).
  246.         /// </summary>
  247.         /// <param name="filePath">File path.</param>
  248.         public static string SHA256(string filePath) {
  249.             using (FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  250.                 SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
  251.                 if (new FileInfo(filePath).Length >= 8192) {
  252.                     byte[] buffer = new byte[8192];
  253.                     int read;
  254.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  255.                         sha256.TransformBlock(buffer, 0, read, buffer, 0);
  256.                     }
  257.                     sha256.TransformFinalBlock(buffer, 0, 0);
  258.                     return ToHexString(sha256.Hash);
  259.                 } else {
  260.                     return ToHexString(sha256.ComputeHash(fileStream));
  261.                 }
  262.             }
  263.         }
  264.  
  265.         /// <summary>
  266.         /// Calculates hash using the 384bits SHA-2 (Secure Hash Algorithm 2).
  267.         /// </summary>
  268.         /// <param name="filePath">File path.</param>
  269.         public static string SHA384(string filePath) {
  270.             using (FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  271.                 SHA384CryptoServiceProvider sha384 = new SHA384CryptoServiceProvider();
  272.                 if (new FileInfo(filePath).Length >= 8192) {
  273.                     byte[] buffer = new byte[8192];
  274.                     int read;
  275.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  276.                         sha384.TransformBlock(buffer, 0, read, buffer, 0);
  277.                     }
  278.                     sha384.TransformFinalBlock(buffer, 0, 0);
  279.                     return ToHexString(sha384.Hash);
  280.                 } else {
  281.                     return ToHexString(sha384.ComputeHash(fileStream));
  282.                 }
  283.             }
  284.         }
  285.  
  286.         /// <summary>
  287.         /// Calculates hash using the 512bits SHA-2 (Secure Hash Algorithm 2).
  288.         /// </summary>
  289.         /// <param name="filePath">File path.</param>
  290.         public static string SHA512(string filePath) {
  291.             using (FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  292.                 SHA512CryptoServiceProvider sha512 = new SHA512CryptoServiceProvider();
  293.                 if (new FileInfo(filePath).Length >= 8192) {
  294.                     byte[] buffer = new byte[8192];
  295.                     int read;
  296.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  297.                         sha512.TransformBlock(buffer, 0, read, buffer, 0);
  298.                     }
  299.                     sha512.TransformFinalBlock(buffer, 0, 0);
  300.                     return ToHexString(sha512.Hash);
  301.                 } else {
  302.                     return ToHexString(sha512.ComputeHash(fileStream));
  303.                 }
  304.             }
  305.         }
  306.  
  307.         /// <summary>
  308.         /// Calculates hash using the MD5 message-digest algorithm.
  309.         /// </summary>
  310.         /// <param name="fileInfo">FileInfo.</param>
  311.         public static string MD5(FileInfo fileInfo) {
  312.             using (FileStream fileStream = File.Open(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  313.                 MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
  314.                 if (fileInfo.Length >= 8192) {
  315.                     byte[] buffer = new byte[8192];
  316.                     int read;
  317.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  318.                         md5.TransformBlock(buffer, 0, read, buffer, 0);
  319.                     }
  320.                     md5.TransformFinalBlock(buffer, 0, 0);
  321.                     return ToHexString(md5.Hash);
  322.                 } else {
  323.                     return ToHexString(md5.ComputeHash(fileStream));
  324.                 }
  325.             }
  326.         }
  327.  
  328.         /// <summary>
  329.         /// Calculates hash using the SHA-1 (Secure Hash Algorithm 1).
  330.         /// </summary>
  331.         /// <param name="fileInfo">FileInfo.</param>
  332.         public static string SHA1(FileInfo fileInfo) {
  333.             using (FileStream fileStream = File.Open(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  334.                 SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
  335.                 if (fileInfo.Length >= 8192) {
  336.                     byte[] buffer = new byte[8192];
  337.                     int read;
  338.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  339.                         sha1.TransformBlock(buffer, 0, read, buffer, 0);
  340.                     }
  341.                     sha1.TransformFinalBlock(buffer, 0, 0);
  342.                     return ToHexString(sha1.Hash);
  343.                 } else {
  344.                     return ToHexString(sha1.ComputeHash(fileStream));
  345.                 }
  346.             }
  347.         }
  348.  
  349.         /// <summary>
  350.         /// Calculates hash using the 256bits SHA-2 (Secure Hash Algorithm 2).
  351.         /// </summary>
  352.         /// <param name="fileInfo">FileInfo.</param>
  353.         public static string SHA256(FileInfo fileInfo) {
  354.             using (FileStream fileStream = File.Open(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  355.                 SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
  356.                 if (fileInfo.Length >= 8192) {
  357.                     byte[] buffer = new byte[8192];
  358.                     int read;
  359.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  360.                         sha256.TransformBlock(buffer, 0, read, buffer, 0);
  361.                     }
  362.                     sha256.TransformFinalBlock(buffer, 0, 0);
  363.                     return ToHexString(sha256.Hash);
  364.                 } else {
  365.                     return ToHexString(sha256.ComputeHash(fileStream));
  366.                 }
  367.             }
  368.         }
  369.  
  370.         /// <summary>
  371.         /// Calculates hash using the 384bits SHA-2 (Secure Hash Algorithm 2).
  372.         /// </summary>
  373.         /// <param name="fileInfo">FileInfo.</param>
  374.         public static string SHA384(FileInfo fileInfo) {
  375.             using (FileStream fileStream = File.Open(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  376.                 SHA384CryptoServiceProvider sha384 = new SHA384CryptoServiceProvider();
  377.                 if (fileInfo.Length >= 8192) {
  378.                     byte[] buffer = new byte[8192];
  379.                     int read;
  380.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  381.                         sha384.TransformBlock(buffer, 0, read, buffer, 0);
  382.                     }
  383.                     sha384.TransformFinalBlock(buffer, 0, 0);
  384.                     return ToHexString(sha384.Hash);
  385.                 } else {
  386.                     return ToHexString(sha384.ComputeHash(fileStream));
  387.                 }
  388.             }
  389.         }
  390.  
  391.         /// <summary>
  392.         /// Calculates hash using the 512bits SHA-2 (Secure Hash Algorithm 2).
  393.         /// </summary>
  394.         /// <param name="fileInfo">FileInfo.</param>
  395.         public static string SHA512(FileInfo fileInfo) {
  396.             using (FileStream fileStream = File.Open(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
  397.                 SHA512CryptoServiceProvider sha512 = new SHA512CryptoServiceProvider();
  398.                 if (fileInfo.Length >= 8192) {
  399.                     byte[] buffer = new byte[8192];
  400.                     int read;
  401.                     while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0) {
  402.                         sha512.TransformBlock(buffer, 0, read, buffer, 0);
  403.                     }
  404.                     sha512.TransformFinalBlock(buffer, 0, 0);
  405.                     return ToHexString(sha512.Hash);
  406.                 } else {
  407.                     return ToHexString(sha512.ComputeHash(fileStream));
  408.                 }
  409.             }
  410.         }
  411.  
  412.         /// <summary>
  413.         /// Calculates hash using selected algorithm.
  414.         /// </summary>
  415.         /// <param name="str">Input string.</param>
  416.         /// <param name="encoding">Encoding the text in the string.</param>
  417.         /// <param name="algorithm">Hash algorithm.</param>
  418.         public static string Compute(string str, Encoding encoding, Algorithm algorithm) {
  419.             switch (algorithm) {
  420.                 case Algorithm.MD5:
  421.                     return MD5(str, encoding);
  422.                 case Algorithm.SHA1:
  423.                     return SHA1(str, encoding);
  424.                 case Algorithm.SHA256:
  425.                     return SHA256(str, encoding);
  426.                 case Algorithm.SHA384:
  427.                     return SHA384(str, encoding);
  428.                 case Algorithm.SHA512:
  429.                     return SHA512(str, encoding);
  430.                 default:
  431.                     return null;
  432.             }
  433.         }
  434.  
  435.         /// <summary>
  436.         /// Calculates hash using selected algorithm.
  437.         /// </summary>
  438.         /// <param name="stream">Input stream.</param>
  439.         /// <param name="algorithm">Hash algorithm.</param>
  440.         public static string Compute(Stream stream, Algorithm algorithm) {
  441.             switch (algorithm) {
  442.                 case Algorithm.MD5:
  443.                     return MD5(stream);
  444.                 case Algorithm.SHA1:
  445.                     return SHA1(stream);
  446.                 case Algorithm.SHA256:
  447.                     return SHA256(stream);
  448.                 case Algorithm.SHA384:
  449.                     return SHA384(stream);
  450.                 case Algorithm.SHA512:
  451.                     return SHA512(stream);
  452.                 default:
  453.                     return null;
  454.             }
  455.         }
  456.  
  457.         /// <summary>
  458.         /// Calculates hash using selected algorithm.
  459.         /// </summary>
  460.         /// <param name="filePath">File path.</param>
  461.         /// <param name="algorithm">Hash algorithm.</param>
  462.         public static string Compute(string filePath, Algorithm algorithm) {
  463.             switch (algorithm) {
  464.                 case Algorithm.MD5:
  465.                     return MD5(filePath);
  466.                 case Algorithm.SHA1:
  467.                     return SHA1(filePath);
  468.                 case Algorithm.SHA256:
  469.                     return SHA256(filePath);
  470.                 case Algorithm.SHA384:
  471.                     return SHA384(filePath);
  472.                 case Algorithm.SHA512:
  473.                     return SHA512(filePath);
  474.                 default:
  475.                     return null;
  476.             }
  477.         }
  478.  
  479.         /// <summary>
  480.         /// Calculates hash using selected algorithm.
  481.         /// </summary>
  482.         /// <param name="fileInfo">FileInfo.</param>
  483.         /// <param name="algorithm">Hash algorithm.</param>
  484.         public static string Compute(FileInfo fileInfo, Algorithm algorithm) {
  485.             switch (algorithm) {
  486.                 case Algorithm.MD5:
  487.                     return MD5(fileInfo);
  488.                 case Algorithm.SHA1:
  489.                     return SHA1(fileInfo);
  490.                 case Algorithm.SHA256:
  491.                     return SHA256(fileInfo);
  492.                 case Algorithm.SHA384:
  493.                     return SHA384(fileInfo);
  494.                 case Algorithm.SHA512:
  495.                     return SHA512(fileInfo);
  496.                 default:
  497.                     return null;
  498.             }
  499.         }
  500.  
  501.         /// <summary>
  502.         /// Hash algorithms.
  503.         /// </summary>
  504.         public enum Algorithm {
  505.             /// <summary>
  506.             /// Undefined hash algorithm.
  507.             /// </summary>
  508.             Undefined,
  509.             /// <summary>
  510.             /// MD5 message-digest algorithm.
  511.             /// </summary>
  512.             MD5,
  513.             /// <summary>
  514.             /// SHA-1 (Secure Hash Algorithm 1).
  515.             /// </summary>
  516.             SHA1,
  517.             /// <summary>
  518.             /// 256bits SHA-2 (Secure Hash Algorithm 2).
  519.             /// </summary>
  520.             SHA256,
  521.             /// <summary>
  522.             /// 384bits SHA-2 (Secure Hash Algorithm 2).
  523.             /// </summary>
  524.             SHA384,
  525.             /// <summary>
  526.             /// 512bits SHA-2 (Secure Hash Algorithm 2).
  527.             /// </summary>
  528.             SHA512
  529.         }
  530.     }
  531. }
  532.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement