asp.net中的RC4加密/解密问题

时间:2011-04-04 07:49:50

标签: asp.net encryption

我已在我的应用程序中实现了RC4加密/解密,如下所示。 在行结束时异常即将来临。

string sFNToBase64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("Malhotra"));
string sEnFirstName = CommonFunction.RC4EncryptDecrypt(sKey, sFNToBase64String);
//calling webservice
localhost.LoginRequest objRQ = new localhost.LoginRequest();
string sIsValidate = objRQ.ValidateRequest(sEnFirstName); //Exception coming on this line

异常来了

 //Exception coming

    The request failed with HTTP status 400: Bad Request. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.Net.WebException: The request failed with HTTP status 400: Bad Request.

我们如何解决它。

----------- UPDATE -------------------

实际上问题只出现在“Malhotra”的加密文本中[加密文字:CX±£þÕlêÁ$]。 我认为Web服务调用不允许有一些特殊字符。

我们如何处理这个?

-----------------------加密/解密过程----------------- ----

//Encrypte
string sEnLastName = CommonFunction.RC4EncryptDecrypt(sKey, "Malhotra");
//Encode
string sLNToBase64String = Convert.ToBase64String(Encoding.ASCII.GetBytes(sEnLastName));
//Decode
string sDecodeLastName = Encoding.ASCII.GetString(Convert.FromBase64String(sLNToBase64String));
//Decrypte
string sDeLastName = CommonFunction.RC4EncryptDecrypt(sKey, sDecodeLastName);

1 个答案:

答案 0 :(得分:1)

第一点 - base64是一种编码标准, NOT 加密。

看起来你将没有base 64编码的加密字符串传递给webservice,这是你的意图吗?

我建议尝试更改此项,如果可能的话,要求将base 64编码的字符串传递给Web服务,并让Web服务在其工作之前从base 64解码回来。

Base 64只能包含A-Z,a-z,0-9,+, - 和=用于填充。这些字符不会导致您的Web服务出现问题。

相关问题