PDA

View Full Version : تبدیل یک فایل c# به php



masiha68
شنبه 10 خرداد 1393, 19:32 عصر
سلام به دوستان تالار سی شارپ
بار اولمه میام اینجا و امیدوارم دست خالی بر نگردم
یه کلاس سی شارپ دارم که میخوام تبدیلش کنم به پی اچ پی
از دوستانی که به هر دو زبان اشنایی دارن خواشمندم یه نگاهی بندازین ببین می تونین کاری انجام بدین :
public class CreateCode {


public string SazBon(string MM)
{
string RET = "";


string[] ME = new string[25];
for (int i = 1; i < MM.Length; i += 2)
{
ME[i] = MM[i - 1].ToString();
}
for (int j = 0; j < MM.Length; j += 2)
{
ME[j] = MM[j + 1].ToString();
}
ME[20] = "9";
ME[21] = "PM";
ME[22] = "89";
ME[23] = "fXC";
ME[24] = "5";
ME[5] = ME[14];
ME[13] = ME[23];
ME[2] = ME[22];
ME[18] = ME[21];
ME[23] = ME[11];
ME[19] = ME[0];


foreach (string item in ME)
{
RET += item;
}





string BACK = Encrypt(RET, RET, 256);


BACK = encryptString(BACK);
return BACK;
}
string encryptString(string strToEncrypt) // md5
{
UTF8Encoding ue = new UTF8Encoding();
byte[] bytes = ue.GetBytes(strToEncrypt);


MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hashBytes = md5.ComputeHash(bytes);


// Bytes to string
return System.Text.RegularExpressions.Regex.Replace
(BitConverter.ToString(hashBytes), "-", "").ToLower();
}




private byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV)
{


MemoryStream ms = new MemoryStream();


Rijndael alg = Rijndael.Create();
alg.Key = Key;


alg.IV = IV;
CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write);


cs.Write(clearData, 0, clearData.Length);
cs.Close();
byte[] encryptedData = ms.ToArray();
return encryptedData;
}
byte[] A;




private string Encrypt(string Data, string Password, int Bits)
{


byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(Data);


PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,


new byte[] { 0x00, 0x01, 0x02, 0x1C, 0x1D, 0x1E, 0x03, 0x04, 0x05, 0x0F, 0x20, 0x21, 0xAD, 0xAF, 0xA4 });


if (Bits == 128)
{
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(16), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
else if (Bits == 192)
{
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(24), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
else if (Bits == 256)
{
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
else
{
return string.Concat(Bits);
}
} // AES

}

masiha68
یک شنبه 11 خرداد 1393, 10:31 صبح
حداقل وایم توضیح بدین هر قسمت چیکار میکنه تا خودم برم دنبال توابع پی اچ پی