using System.Security.Cryptography;
var result = createXmlRequest("123", "Michael", "1234", "10");
var query = result.Descendants().Where(x => x.Name.LocalName == "InitiateAsyncTransaction_Request");
string xml = string.Empty;
foreach (var xElem in query)
Console.WriteLine("Number of elements:{0}", query.Count());
string hashKey = Hash.GetHash(xml, HashType.SHA256);
Console.WriteLine("Hashkey:{0}", hashKey);
private XElement createXmlRequest(string pCode, string pName, string pUniqueIdentifier, string pAmount)
XNamespace ns = "http://schema.inteliscape.com/message/v1";
XNamespace ns1 = "http://schema.inteliscape.com/paymentengine/integration/v1";
XNamespace ns2 = "http://schema.inteliscape.com/common/v1";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
new XElement(ns + "Message",
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"),
new XAttribute("xmlns", "http://schema.inteliscape.com/message/v1"),
new XElement(ns + "Version", 1),
new XElement(ns + "Header",
new XElement(ns + "Details",
new XElement(ns + "Source", "CeGG.Demo.PaymentEngine.Client"),
new XElement(ns + "Destination", "PaymentEngine"),
new XElement(ns + "Command", "PE_InitiateAsyncTransaction"),
new XElement(ns + "Qualifier", "Request")
new XElement(ns + "Sender",
new XElement(ns + "SenderId", "DEMO-DITS-PE"),
new XElement(ns + "Authentication",
new XElement(ns + "Method", "SHA256"),
new XElement(ns + "Value", "7LnPeLEnFgCZ0ml1+gytc6CtAwzm4p6VCvqCz0r4JjU="),
new XElement(ns + "HashMode", "Advance")
new XElement(ns + "Errors"),
new XElement(ns + "Body",
new XElement(ns1 + "InitiateAsyncTransaction_Request",
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"),
new XAttribute("xmlns", "http://schema.inteliscape.com/paymentengine/integration/v1"),
new XElement(ns1 + "CreateToken", false),
new XElement(ns1 + "Info",
new XElement(ns1 + "Citizen",
new XElement(ns1 + "Individual",
new XElement(ns2 + "Code", pCode),
new XElement(ns2 + "Name", pName),
new XElement(ns2 + "UniqueIdentifier", pUniqueIdentifier)
new XElement(ns1 + "Representative", new XAttribute(xsi + "nil", true)),
new XElement(ns1 + "PaymentMethodCode", "PM-0005"),
new XElement(ns1 + "Amount", pAmount),
new XElement(ns1 + "CurrencyIsoAlphaCode", "EUR"),
new XElement(ns1 + "LanguageCode", "en"),
new XElement(ns1 + "ClientTransactionNo", "262c1a20-0f07-45e3-827c-c50d26aa02ee"),
new XElement(ns1 + "IpAddress", "127.0.0.1")
public static string GetHash(string text, HashType hashType)
hashString = GetMD5(text);
hashString = GetSHA1(text);
hashString = GetSHA256(text);
hashString = GetSHA512(text);
hashString = "Invalid Hash Type";
public static bool CheckHash(string original, string hashString, HashType hashType)
string originalHash = GetHash(original, hashType);
return (originalHash == hashString);
private static string GetMD5(string text)
UnicodeEncoding UE = new UnicodeEncoding();
byte[] message = UE.GetBytes(text);
MD5 hashString = new MD5CryptoServiceProvider();
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
hex += String.Format("{0:x2}", x);
private static string GetSHA1(string text)
UnicodeEncoding UE = new UnicodeEncoding();
byte[] message = UE.GetBytes(text);
SHA1Managed hashString = new SHA1Managed();
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
hex += String.Format("{0:x2}", x);
private static string GetSHA256(string text)
UnicodeEncoding UE = new UnicodeEncoding();
byte[] message = UE.GetBytes(text);
SHA256Managed hashString = new SHA256Managed();
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
hex += String.Format("{0:x2}", x);
private static string GetSHA512(string text)
UnicodeEncoding UE = new UnicodeEncoding();
byte[] message = UE.GetBytes(text);
SHA512Managed hashString = new SHA512Managed();
hashValue = hashString.ComputeHash(message);
foreach (byte x in hashValue)
hex += String.Format("{0:x2}", x);