哪位帅哥把这2个c#方法,给转成php5.5的方法。谢谢!!! [ 2.0 版本 ]
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();
}
最佳答案
-
ZendLaravelYii 发布于 2015-08-31 15:42 举报
额,重点是你看了C#代码了么,有些定义类中,根本不存在无法引用。
如果明白自己的功能需求,何必硬要在网上百度来的C#代码进行PHP转换,倒不如自己思考用PHP写。
直接问需求是什么好了。共 1 条回复liufafafa 觉得很赞
其他 1 个回答
xjdata
注册时间:2011-12-07
最后登录:2021-07-09
在线时长:112小时28分
最后登录:2021-07-09
在线时长:112小时28分
- 粉丝23
- 金钱14169
- 威望75
- 积分16039