ASP.NET uses jQuery AJAX to achieve MD5 encryption example

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

A asp.net Ajax example, the use of jQuery, the realization of MD5 encryption. In.NET 4, Visual Studio 2010 is running successfully.

Effect of experience:

Front end code(md5.htm):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MD5 encryption using asp.net jQuery ajax- Ke Leyi</title>
<script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script>
<!--Please connect to the network-->
</head>
<body>
<div>
<h3>MD5 encryption</h3>
Please input string to be encrypted: <input type="text" id="input_keleyi_com" style="width:250px;"/>
<br />
<span id="Md5Type">
<input id="Md5Type_1" type="radio" name="md5type_keleyi_com" value="1" checked="checked" /><label for="Md5Type_1">32 [large]</label>
<input id="Md5Type_2" type="radio" name="md5type_keleyi_com" value="2" /><label for="Md5Type_2">32 [small]</label>
<input id="Md5Type_3" type="radio" name="md5type_keleyi_com" value="3" /><label for="Md5Type_3">16 [large]</label>
<input id="Md5Type_4" type="radio" name="md5type_keleyi_com" value="4" /><label for="Md5Type_4">16 [small]</label>
</span><input type="button" value="Encryption" onclick="javascript:Md5Ajax();" />
<br />
Result: <input id="MD5Result_keleyi_com" type="text" style="width:450px" />
</div>

<script type="text/javascript">
function Md5Ajax() {
var k_input = $("#input_ke" + "leyi_com").val();
var k_format = $('input[name="md5type_keleyi_com"]:checked').val();
$.ajax({
type: "Post",
url: "KeleyiMd5.aspx/GetMd5",
data: "{'input':'" + k_input + "','format':'" + k_format + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if ((String)(data.d) != "-1") {
$("#MD5Result_k"+"eleyi_com").val(data.d);
}
else
alert('Encryption failed');
},
error: function (err) {
alert('Ke to remind you: wrong' + err);
}
});
}
</script>
</body>
</html>

This paper uses the Ajax method of the jQuery, please reference: and

More information:   (JavaScript AJAX instance)

The KeleyiMd5.aspx file code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="KeleyiMd5.aspx.cs" Inherits="Keleyi.Com.KeleyiAjax.KeleyiMd5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Asp.net jQuery Ajax example of MD5 encryption - Ke Leyi</title>
</head>
<body>
<div>
<a href="http://tool.keleyi.com/t/md5.htm">See the effect</a>
<br />
<img src="http://keleyi.com/image/a/tvh00n12.jpg" alt="Kang Yikun" />
</div>
</body>
</html>

This example is the asp.net Ajax example, asp.net MVC Ajax please refer to:

Code behind(KeleyiMd5.aspx.cs):

using System;
using System.Web.Services;

namespace Keleyi.Com.KeleyiAjax
{
public partial class KeleyiMd5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

/// <summary>
/// 
/// </summary>
/// <param name="input"></param>
/// <param name="format">1 32 2 32 lowercase uppercase, say, 3 said 16 caps, 4 and 16 lower case</param>
/// <returns></returns>
[WebMethod]
public static string GetMd5(string input, int format)
{
switch (format)
{
case 1:
return GetMd5Upper32(input);
case 2:
return GetMd5Upper32(input).ToLower();
case 3:
return GetMd5Upper32(input).Substring(8, 16);
case 4:
return GetMd5Upper32(input).Substring(8, 16).ToLower();
default:
return GetMd5Upper32(input);
}
}

static string GetMd5Upper32(string input)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(input, "MD5");
}
}
}

The source code download: https://keleyi.codeplex.com/releases/view/111763

The original

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Becky at November 15, 2013 - 1:47 PM