python转换成c#

2024-12-31 03:38:36
推荐回答(1个)
回答1:

using System.Security.Cryptography;
public string Decrypt(string pToDecrypt, string sKey)
        {
            byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
            using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
            {
                des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(inputByteArray, 0, inputByteArray.Length);
                    cs.FlushFinalBlock();
                    cs.Close();
                }
                string str = Encoding.UTF8.GetString(ms.ToArray());
                ms.Close();
                return str;
            }
        }
byte[] byData = new byte[100000];
char[] charData = new char[1000000];
try
{
FileStream sFile = new FileStream("config.bin",FileMode.Open);
sFile.Read(byData, 0, 100);
}
catch (IOException e)
{
return;
}
String result=Decruypt(byData.ToString(), "\xE3\xA5\xE3\xA5\xE3\xA5\xE3\xA5\")