Skip to content

Commit 08ca42e

Browse files
changed from MD5 to SHA256 (#12)
1 parent c89e39b commit 08ca42e

File tree

5 files changed

+71
-71
lines changed

5 files changed

+71
-71
lines changed

AjaxPro/AjaxPro.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
<Compile Include="Utilities\Constant.cs">
260260
<SubType>Code</SubType>
261261
</Compile>
262-
<Compile Include="Utilities\MD5Helper.cs">
262+
<Compile Include="Utilities\HashHelper.cs">
263263
<SubType>Code</SubType>
264264
</Compile>
265265
<Compile Include="Utilities\Utility.cs">

AjaxPro/Handler/ConverterJavaScriptHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void ProcessRequest(HttpContext context)
9393
}
9494
}
9595

96-
etag = MD5Helper.GetHash(System.Text.Encoding.Default.GetBytes("converter"));
96+
etag = Hash5Helper.GetHash(System.Text.Encoding.Default.GetBytes("converter"));
9797

9898
DateTime now = DateTime.Now;
9999
DateTime lastMod = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); //.ToUniversalTime();

AjaxPro/Handler/EmbeddedJavaScriptHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void ProcessRequest(HttpContext context)
104104
}
105105
}
106106

107-
etag = MD5Helper.GetHash(System.Text.Encoding.Default.GetBytes(fileName));
107+
etag = Hash5Helper.GetHash(System.Text.Encoding.Default.GetBytes(fileName));
108108

109109
DateTime now = DateTime.Now;
110110
DateTime lastMod = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); //.ToUniversalTime();

AjaxPro/Handler/TypeJavaScriptHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void ProcessRequest(HttpContext context)
146146
}
147147

148148
etag = type.AssemblyQualifiedName;
149-
etag = MD5Helper.GetHash(System.Text.Encoding.Default.GetBytes(etag));
149+
etag = Hash5Helper.GetHash(System.Text.Encoding.Default.GetBytes(etag));
150150

151151
DateTime now = DateTime.Now;
152152
DateTime lastMod = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); // .ToUniversalTime();
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,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-
*
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

Comments
 (0)