请问那位朋友可以帮忙把这 2 个 c# 方法,给转成 PHP5.5 的方法吗?谢谢。
大家好,本人php菜鸟一枚,现在正在边工作边学习php,遇到一个c#方法转为php方法的问题。实在没办法了,只有发帖求助,还请哪位朋友帮忙,将以下2个方法转换为php的方法,不胜感激!
当然,我明白,第一天注册,第一个帖子就是索取,这样的行为很被人不齿,但是迫于无奈,还是希望能够得到某位朋友的帮助,谢谢你。
当然,我明白,第一天注册,第一个帖子就是索取,这样的行为很被人不齿,但是迫于无奈,还是希望能够得到某位朋友的帮助,谢谢你。
public static string Decrypt(string Text, string sKey)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
int num = Text.Length / 2;
byte[] buffer = new byte[num];
for (int i = 0; i < num; i++)
{
int num3 = Convert.ToInt32(Text.Substring(i * 2, 2), 0x10);
buffer[i] = (byte) num3;
}
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
return Encoding.Default.GetString(stream.ToArray());
}
public static string Encrypt(string Text, string sKey)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
byte[] bytes = Encoding.Default.GetBytes(Text);
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
stream2.Write(bytes, 0, bytes.Length);
stream2.FlushFinalBlock();
StringBuilder builder = new StringBuilder();
foreach (byte num in stream.ToArray())
{
builder.AppendFormat("{0:X2}", num);
}
return builder.ToString();
}
1 个回复
xjdata
赞同来自: