using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Security.Cryptography;
public static void Main()
string traffic_news_url = "https://deaapim3.azure-api.net/TrafficNews/v1/ryg_service_status.xml";
HttpClient hc1 = new HttpClient();
hc1.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "f31712ef380a41da89a1c1c5c04c5929");
HttpResponseMessage response1 = hc1.GetAsync(traffic_news_url).Result;
string rtnEncryptKey = response1.Content.ReadAsStringAsync().Result;
Console.WriteLine("rtnEncryptKey : "+rtnEncryptKey);
string result = Decrypt(rtnEncryptKey, "TNCMstag070815");
result = "<ryg_status>" + result.Remove(0, result.IndexOf("<line>"));
Console.WriteLine("result === ");
Console.WriteLine(result);
XmlDocument xmlDoc = new XmlDocument();
XmlElement root = xmlDoc.DocumentElement;
XmlNodeList nodeList = xmlDoc.DocumentElement.FirstChild.ChildNodes;
foreach (XmlElement xe in nodeList)
Console.WriteLine("xe.InnerText ~~~ ");
Console.WriteLine(xe.InnerText);
Console.WriteLine("xe.Attributes.Count ~~~ ");
Console.WriteLine(xe.Attributes.Count);
for (int i = 0; i < xe.Attributes.Count; i++){
Console.WriteLine("xe.Attributes[i].Name ~~~ ");
Console.WriteLine(xe.Attributes[i].Name);
Console.WriteLine("nodeList ~~ " + nodeList);
Console.WriteLine("Count ~~ " + xmlDoc.ChildNodes.Count);
Console.WriteLine("[1].Name ~~ " + xmlDoc.ChildNodes[1].Name);
public static string Decrypt(string Data, string key)
var result = string.Empty;
RijndaelManaged rijalg = new RijndaelManaged();
rijalg.Padding = PaddingMode.PKCS7;
rijalg.Mode = CipherMode.CBC;
rijalg.Key = HexStringToByte(getHashSha256(key));
byte[] encryptedData = Convert.FromBase64String(RemoveSpecialCharacters(Data));
ICryptoTransform decryptor = rijalg.CreateDecryptor();
using (MemoryStream msDecrypt = new MemoryStream(encryptedData))
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
result = srDecrypt.ReadToEnd();
public static byte[] HexStringToByte(string hexString)
int bytesCount = (hexString.Length) / 2;
byte[] bytes = new byte[bytesCount];
for (int x = 0; x < bytesCount; ++x)
bytes[x] = Convert.ToByte(hexString.Substring(x * 2, 2), 16);
public static string getHashSha256(string text)
byte[] bytes = Encoding.UTF8.GetBytes(text);
SHA256Managed hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
string hashString = string.Empty;
hashString += String.Format("{0:x2}", x);
public static string RemoveSpecialCharacters(string strData)
var charList = new List<char>();
for (int i = 0; i < strData.Length; i++)
var charItem = strData[i];
return string.Join(string.Empty, charList);