Re: Hvað ertu með copy'að ?
Sent: Mið 02. Des 2009 20:42
"http://www.youtube.com/watch?v=Yk_-4HQ4RSg "
Sá þetta á forsíðunni á youtube og varð forvitinn
Sá þetta á forsíðunni á youtube og varð forvitinn
Allinn skrifaði:http://www.youtube.com/watch?v=fpqMBtxodj0
Kóði: Velja allt
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;
namespace eXceLSior.Components
{
using System.Security;
using System.Security.Cryptography;
public class DigestAdapter : IAdapter
{
public string Process(string input)
{
byte[] hash;
switch (Type)
{
case DigestType.HMACRIPEMD160:
{
using (var algorithm = new HMACRIPEMD160())
{
string test = "<request><hashkey>asdf</hashkey><hashvalue>" + input + "</hashvalue></request>";
XPathNavigator navigator = test.AsXPathNavigator();
string key = navigator.SelectSingleNode("/request/hashkey").InnerXml;
algorithm.Key = Encoding.ASCII.GetBytes(key);
string value = navigator.SelectSingleNode("/request/hashvalue").InnerXml;
hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(value));
break;
}
}
case DigestType.MD5:
hash = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(input));
break;
case DigestType.SHA1:
hash = new SHA1CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(input));
break;
case DigestType.SHA256:
hash = new SHA256CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(input));
break;
case DigestType.SHA384:
hash = new SHA384CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(input));
break;
case DigestType.SHA512:
hash = new SHA512CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(input));
break;
default:
return input;
}
StringBuilder sb = new StringBuilder(hash.Length);
foreach (byte b in hash)
sb.Append(String.Format("{0:x4}", b));
return sb.ToString();
}
public string Process(XPathNavigator input)
{
return String.Empty;
}
public DigestType Type
{
get;
set;
}
}
}