开发者

RC4 encryption/decryption problem in asp.net

开发者 https://www.devze.com 2023-02-22 08:55 出处:网络
I have implemented RC4 encryption/decryption in my application as given below. at the end of the line exception coming.

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 sLNT开发者_JS百科oBase64String = Convert.ToBase64String(Encoding.ASCII.GetBytes(sEnLastName));
//Decode
string sDecodeLastName = Encoding.ASCII.GetString(Convert.FromBase64String(sLNToBase64String));
//Decrypte
string sDeLastName = CommonFunction.RC4EncryptDecrypt(sKey, sDecodeLastName);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号