110,568
社区成员
发帖
与我相关
我的任务
分享
$.ajax({
type: "get",
async: false,
url: 'http://www.domain1.com/inf/WebService_DESClass.asmx/EncryptDES',
data: { encryptString:str, encryptKey:encryptKey },
dataType: "jsonp",
jsonp: 'callback',
jsonpCallback: 'sucallback',
success: function (data) {
alert(data.d);
// window.location.href = "http://www.domain1.com/Appointment/Index?str=" + data.d;
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert('加载出错了!' + XmlHttpRequest.status);
}
});
[WebMethod]
public string EncryptDES(string encryptString, string encryptKey)
{
string callback = HttpContext.Current.Request.Params["callback"];
try
{
byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
byte[] rgbIV = Keys;
byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return callback + "({'d':'" + Convert.ToBase64String(mStream.ToArray()) + "'})";
//return Convert.ToBase64String(mStream.ToArray());
}
catch(Exception e)
{
throw e;
// // HttpContext.Current.Response.Write(callback + "(" + encryptString + ")");
// //HttpContext.Current.Response.End();
}
}