C#中的RC4加密代码有什么问题吗
发布时间:2020-12-16 00:17:35 所属栏目:百科 来源:网络整理
导读:我试图在C#中收听 Foxycart XML Datafeed并遇到一个归结为加密的问题. 简而言之,他们使用RC4 encryption将数据作为编码和加密的XML发送. 为了测试,他们有some (user submitted) sample code to test this with C#.我尝试使用其中一个用户提供的这个示例RC4解
我试图在C#中收听
Foxycart
XML Datafeed并遇到一个归结为加密的问题.
简而言之,他们使用RC4 encryption将数据作为编码和加密的XML发送. 为了测试,他们有some (user submitted) sample code to test this with C#.我尝试使用其中一个用户提供的这个示例RC4解密代码,但它似乎不起作用,他们的支持人员认为它使用C#RC4算法.由于他们不是C#专家,我想我会问这里.这是the post on the FoxyCart forum 无论如何,这里是(试图)通过加密XML文件并将其发布到URL来模拟响应的代码(注意,DataFeedKey是我已存储为成员变量的字符串): public ActionResult TestDataFeed() { string transactionData = (new StreamReader(@"D:SampleFeed.xml")).ReadToEnd(); string encryptedTransactionData = RC4.Encrypt(DataFeedKey,transactionData,false); string encodedTransactionData = HttpUtility.UrlEncode(encryptedTransactionData,Encoding.GetEncoding(1252)); string postData = "FoxyData=" + encodedTransactionData; var req = (HttpWebRequest)WebRequest.Create("http://localhost:3396/FoxyCart/RecieveDataFeed"); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; var sw = new StreamWriter(req.GetRequestStream(),Encoding.ASCII); sw.Write(postData); sw.Close(); HttpWebResponse resp = null; try { resp = (HttpWebResponse)req.GetResponse(); string r = new StreamReader(resp.GetResponseStream()).ReadToEnd(); } catch (WebException ex) { string err = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); } return null; } 这是接收响应的回调方法. [ValidateInput(false)] public ActionResult RecieveDataFeed(FormCollection collection) { string unencodedFeed = HttpUtility.UrlDecode(collection["FoxyData"],Encoding.GetEncoding(1252)); string transaction = RC4.Decrypt(DataFeedKey,unencodedFeed,false); return Content("foxy"); } 而不是在这个问题中内联整个RC4类,here is a link to the code of this RC4 class. 正如我在问题顶部的上述链接中发布的那样,问题是当我检查内部的变量事务时 RecieveDataFeed() 方法,我应该有常规XML回来,但我看到这个: é?x?′ v′“?·8êU?í¥M?S?J?ó5C?7?…?lT&tòG·?Yù3<í???úüF???ìNμ>4|?u÷??;£-w¤??êyL1??èíY??’é(μJ?~??=3?]F??=±ùí]'é3?"?P?{ù^yyé?–°?…5eWF$zén?^_”X?’?%?-5á ò? |