|
1 |
| -/* |
2 |
| - * MD5Helper.cs |
3 |
| - * |
4 |
| - * Copyright © 2007 Michael Schwarz (http://www.ajaxpro.info). |
5 |
| - * All Rights Reserved. |
6 |
| - * |
7 |
| - * Permission is hereby granted, free of charge, to any person |
8 |
| - * obtaining a copy of this software and associated documentation |
9 |
| - * files (the "Software"), to deal in the Software without |
10 |
| - * restriction, including without limitation the rights to use, |
11 |
| - * copy, modify, merge, publish, distribute, sublicense, and/or |
12 |
| - * sell copies of the Software, and to permit persons to whom the |
13 |
| - * Software is furnished to do so, subject to the following conditions: |
14 |
| - * |
15 |
| - * The above copyright notice and this permission notice shall be |
16 |
| - * included in all copies or substantial portions of the Software. |
17 |
| - * |
18 |
| - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
19 |
| - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
20 |
| - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
21 |
| - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
22 |
| - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
23 |
| - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
24 |
| - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
25 |
| - */ |
26 |
| -/* |
27 |
| - * MS 07-04-12 changed MD5 compute hash (using BitConverter, now) |
28 |
| - * |
29 |
| - * |
30 |
| - */ |
31 |
| -using System; |
32 |
| -using System.Text; |
33 |
| -using System.Security.Cryptography; |
34 |
| - |
35 |
| -namespace AjaxPro |
36 |
| -{ |
37 |
| - /// <summary> |
38 |
| - /// Provides methods to get a MD5 hash from a string or byte array. |
39 |
| - /// </summary> |
40 |
| - public class MD5Helper |
41 |
| - { |
42 |
| - /// <summary> |
43 |
| - /// Gets the hash. |
44 |
| - /// </summary> |
45 |
| - /// <param name="data">The data.</param> |
46 |
| - /// <returns></returns> |
47 |
| - public static string GetHash(string data) |
48 |
| - { |
49 |
| - byte[] b = System.Text.Encoding.Default.GetBytes(data); |
50 |
| - |
51 |
| - return GetHash(b); |
52 |
| - } |
53 |
| - |
54 |
| - /// <summary> |
55 |
| - /// Gets the hash. |
56 |
| - /// </summary> |
57 |
| - /// <param name="data">The data.</param> |
58 |
| - /// <returns></returns> |
59 |
| - public static string GetHash(byte[] data) |
60 |
| - { |
61 |
| - // This is one implementation of the abstract class MD5. |
62 |
| - MD5 md5 = new MD5CryptoServiceProvider(); |
63 |
| - |
64 |
| - return BitConverter.ToString(md5.ComputeHash(data)).Replace("-", String.Empty); |
65 |
| - } |
66 |
| - } |
67 |
| -} |
| 1 | +/* |
| 2 | + * MD5Helper.cs |
| 3 | + * |
| 4 | + * Copyright © 2007 Michael Schwarz (http://www.ajaxpro.info). |
| 5 | + * All Rights Reserved. |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person |
| 8 | + * obtaining a copy of this software and associated documentation |
| 9 | + * files (the "Software"), to deal in the Software without |
| 10 | + * restriction, including without limitation the rights to use, |
| 11 | + * copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | + * sell copies of the Software, and to permit persons to whom the |
| 13 | + * Software is furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be |
| 16 | + * included in all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 20 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 22 | + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 23 | + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | + */ |
| 26 | +/* |
| 27 | + * MS 07-04-12 changed MD5 compute hash (using BitConverter, now) |
| 28 | + * MS 21-12-22 changed hash algorithm from MD5 to SHA256 |
| 29 | + * |
| 30 | + */ |
| 31 | +using System; |
| 32 | +using System.Text; |
| 33 | +using System.Security.Cryptography; |
| 34 | + |
| 35 | +namespace AjaxPro |
| 36 | +{ |
| 37 | + /// <summary> |
| 38 | + /// Provides methods to get a MD5 hash from a string or byte array. |
| 39 | + /// </summary> |
| 40 | + public class Hash5Helper |
| 41 | + { |
| 42 | + /// <summary> |
| 43 | + /// Gets the hash. |
| 44 | + /// </summary> |
| 45 | + /// <param name="data">The data.</param> |
| 46 | + /// <returns></returns> |
| 47 | + public static string GetHash(string data) |
| 48 | + { |
| 49 | + byte[] b = System.Text.Encoding.Default.GetBytes(data); |
| 50 | + |
| 51 | + return GetHash(b); |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Gets the hash. |
| 56 | + /// </summary> |
| 57 | + /// <param name="data">The data.</param> |
| 58 | + /// <returns></returns> |
| 59 | + public static string GetHash(byte[] data) |
| 60 | + { |
| 61 | + // This is one implementation of the abstract class MD5. |
| 62 | + MD5 md5 = new MD5CryptoServiceProvider(); |
| 63 | + |
| 64 | + return BitConverter.ToString(new SHA256Managed().ComputeHash(data)).Replace("-", String.Empty); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments