大家好,本人 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 ();
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.