大家好,本人 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
zhuangzhuang1988 2015-08-30 07:37:14 +08:00
这种伸手问题, 给点钱就能解决的.
|
2
oott123 2015-08-30 07:51:35 +08:00 via Android
200 块我接,俩函数一个 100 块
|
3
realpg 2015-08-30 10:50:15 +08:00
楼上太黑了 差评
俩函数打包 160 元,单做一个 90 …… |
5
uglyer 2015-08-30 11:10:32 +08:00
楼主明白还来伸手。
|
6
crab 2015-08-30 11:38:31 +08:00
你可以发 2 个帖子,第 1 贴问这段 C#是什么意思。第 2 贴问能不能用 PHP 写出这样的功能。
|
7
xjdata OP 解决了。 谢谢各位的热心。
|
8
lbp0200 2015-09-06 16:03:29 +08:00
这就是 md5 加解密嘛
|