asp.net中的RC4加密/解密问题
我已经在我的应用程序中实现了 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.
我们该如何解决。
---------更新--------------------------------
实际上问题仅出在“Malhotra”的加密文本上[密文:CX±£þlêÁ$]。 我认为网络服务调用不允许使用一些特殊字符。
我们该如何处理这个问题呢?
--------------------------------加密/解密过程-------------------- -
//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);
I have implemented RC4 encryption/decryption in my application as given below.
at the end of the line exception coming.
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 comes
//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.
How can we resolve it.
-----------UPDATE-------------------
Actually the problem is only with encrypted text of "Malhotra"[ encrypted text: CX±£þÕlêÁ$].
i think there are some special characters that web service call doesn't allow.
How can we handle this one?
-----------------------Encrypted/Decrypted Process---------------------
//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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一点 - base64 是一种编码标准,不是加密。
看起来好像您正在将没有 Base 64 编码的加密字符串传递给 Web 服务,这是您的意图吗?
如果可能的话,我建议尝试更改此设置,要求将 Base 64 编码的字符串传递给 Web 服务,并让 Web 服务在工作之前从 Base 64 解码回来。
Base 64 只能包含 AZ、az、0-9、+、- 和 = 用于填充。这些字符不会导致您的网络服务出现问题。
First point - base64 is an encoding standard, NOT encryption.
It looks as though you are passing the encrypted string without base 64 encoding to the webservice, is this your intention?
I would suggest trying to change this, if possible, to require the base 64 encoded string to be passed to the webservice, and for the web service to decode back from base 64 before it does its work.
Base 64 can only contain A-Z, a-z, 0-9, +, -, and = for padding. These characters will not cause issues with your webservice.