var result=CryptoJS.AES.decrypt(data,name).toString(CryptoJS.enc.Utf8);
我尝试使用cryptojs
解密json数据。我想在c#中使用这段代码。这需要哪些库/库?它给出了错误CryptoJs does not exist in current context
。
我用这个
public static void Main(string [] args) {
Class1 class1obj = new Class1();
string baseUrl = "http://www.whatsonindia.com";
WebRequest request = HttpWebRequest.Create(baseUrl);
WebResponse response = request.GetResponse();
string cookiesVals = response.Headers[HttpResponseHeader.SetCookie];
string url = "http://www.whatsonindia.com/appi/user?channelgenre=all&context=applicationname%3Dsourcebits%3Bheadendid%3D0&dateselected=0&mode=getTVGuideInfo&pageno=1&responseformat=json&responselanguage=English&starthour=0&totalhrdata=24&userid=-1";
WebClient client = new WebClient();
client.Headers.Add(HttpRequestHeader.Cookie, cookiesVals);
var data = client.DownloadString(url);
Console.WriteLine(data);
Console.WriteLine("dynamic object....");
Console.ReadLine();
JavaScriptSerializer serializer = new JavaScriptSerializer();
dynamic item = serializer.Deserialize<object>(data);
string name = item["pki"];
//JavaScriptSerializer serializer1 = new JavaScriptSerializer();
var result=CryptoJS.AES.decrypt(data,name).toString(CryptoJS.enc.Utf8);
var obj = (JObject)JsonConvert.DeserializeObject(data);
// var dict = obj.First.First.Children().Cast<JProperty>().ToDictionary();
var dt = (string)obj["data"];
Console.WriteLine(dt);
Console.ReadLine();
}
答案 0 :(得分:1)
CryptoJS是JavaScript库,不能在C#项目中使用。要在C#中进行AES解密,您需要使用.Net加密库,这个库包含在这个答案中:Using AES encryption in C#。
在上面的链接答案中,您将看到解密字符串的行:
string decrypted = DecryptStringFromBytes(encrypted, myRijndael.Key, myRijndael.IV);
第二个参数是你可以传递密钥的地方(我假设pki是你用来加密字符串的字节数组键)。第3个参数是您在加密字符串时应确保与CryptoJS同步的算法类型。