Fetion decrypt Password

Source: Internet
Author: User
private void button1_Click(object sender, EventArgs e){    XmlDocument doc = new XmlDocument();    doc.Load(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"/Fetion/Configuration.dat");    doc.InnerXml = XMLDecodeHelper.DecodeXML(doc);    XmlNode node = doc.SelectSingleNode("/ImpsConfiguration/AccountsData/Accounts");    XmlNode node2 = doc.SelectSingleNode("/ImpsConfiguration/AccountsData/Mappings");    this.listView1.Items.Clear();    foreach (XmlNode node3 in node.ChildNodes)    {        ListViewItem item = new ListViewItem();        string str = node3.Attributes["id"].Value;        item.Text = str;        this.listView1.Items.Add(item);        foreach (XmlNode node4 in node2.ChildNodes)        {            if (node4.Attributes["mobile-no"].Value == str)            {                item.SubItems.Add(node4.Attributes["sid"].Value);                break;            }        }        if (node3.Attributes["password"] != null)        {            item.SubItems.Add(SecurityHelper.DecryptPassword(node3.Attributes["password"].Value));            continue;        }        item.SubItems.Add("(password not saved)");    }}

 

public static class SecurityHelper{    // Fields    private static string _secToken = WindowsIdentity.GetCurrent().User.Value;    public static readonly byte[] RgbIV = new byte[] { 0x1f, 0x4e, 0x81, 12, 0xa8, 0x20, 0xfe, 0x42 };    // Methods    public static string DecryptPassword(string text)    {        if (text.Length <= 0)        {            return string.Empty;        }        return InnerDecrypt(Convert.FromBase64String(text), _secToken);    }    public static string EncryptPass(string sid, string domain, string oldPass, string newPass)    {        string s = sid + ":" + domain + ":" + oldPass;        byte[] bytes = Encoding.UTF8.GetBytes(s);        byte[] buffer2 = new MD5CryptoServiceProvider().ComputeHash(bytes);        string str2 = StringHelper.Hex2Str(buffer2) + ":" + newPass;        TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();        provider.Key = buffer2;        MemoryStream stream = new MemoryStream();        using (CryptoStream stream2 = new CryptoStream(stream, new TripleDESCryptoServiceProvider().CreateEncryptor(buffer2, RgbIV), CryptoStreamMode.Write))        {            byte[] buffer = Encoding.UTF8.GetBytes(str2);            stream2.Write(buffer, 0, buffer.Length);            stream2.FlushFinalBlock();            stream2.Close();        }        byte[] buffer4 = stream.ToArray();        stream.Close();        return StringHelper.Hex2Str(buffer4);    }    public static string EncryptPassword(string plain)    {        if (plain.Length <= 0)        {            return string.Empty;        }        return Convert.ToBase64String(InnerEncrypt(plain, _secToken));    }    private static string InnerDecrypt(byte[] buffer, string keyToken)    {        byte[] bytes = Encoding.UTF8.GetBytes(keyToken);        byte[] rgbKey = new MD5CryptoServiceProvider().ComputeHash(bytes);        MemoryStream stream = new MemoryStream(buffer, false);        using (CryptoStream stream2 = new CryptoStream(stream, new TripleDESCryptoServiceProvider().CreateDecryptor(rgbKey, RgbIV), CryptoStreamMode.Read))        {            StreamReader reader = new StreamReader(stream2);            return reader.ReadToEnd();        }    }    private static byte[] InnerEncrypt(string text, string keyToken)    {        byte[] bytes = Encoding.UTF8.GetBytes(keyToken);        byte[] rgbKey = new MD5CryptoServiceProvider().ComputeHash(bytes);        MemoryStream stream = new MemoryStream();        using (CryptoStream stream2 = new CryptoStream(stream, new TripleDESCryptoServiceProvider().CreateEncryptor(rgbKey, RgbIV), CryptoStreamMode.Write))        {            byte[] buffer = Encoding.UTF8.GetBytes(text);            stream2.Write(buffer, 0, buffer.Length);            stream2.FlushFinalBlock();            stream2.Close();        }        return stream.ToArray();    }}
Collapse Methods

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.