PHP函数转换 急急急

DiscussQuestions 2011-06-01 02:44:23
php中的hash_hmac函数和base64_encode函数
在C#中有类似的方法吗?
帮我把这两个函数翻译成C#,急急急!!在线等待!!!
...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
www_7di_net 2011-06-01
  • 打赏
  • 举报
回复


using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace eName.Payment
{
public class HMAC
{
private string Fun_MD5(string str)
{
byte[] b = Encoding.GetEncoding(1252).GetBytes(str);
b = new MD5CryptoServiceProvider().ComputeHash(b);
string ret = string.Empty;
foreach (int i in b)
{
ret += i.ToString("x").PadLeft(2, '0');
}
return ret;
}
private byte[] HexStringToArray(string HexStr)
{
string HEX = "0123456789ABCDEF";
string str = HexStr.ToUpper();
int len = str.Length;
byte[] retByte = new byte[len / 2];
for (int i = 0; i < len / 2; i++)
{
int NumHigh = HEX.IndexOf(str[i * 2]);
int NumLow = HEX.IndexOf(str[i * 2 + 1]);
retByte[i] = Convert.ToByte(NumHigh * 16 + NumLow);
}
return retByte;
}
private string StrXor(string password, string pad)
{
string iResult = string.Empty;
int KLen = password.Length;

for (int i = 0; i < 64; i++)
{
if (i < KLen)
iResult += Convert.ToChar(pad[i] ^ password[i]);
else
iResult += Convert.ToChar(pad[i]);
}
return iResult;
}
public string Maker(string data, string password)
{
string k_ipad, k_opad, temp;
string ipad = "6666666666666666666666666666666666666666666666666666666666666666";
string opad = @"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\";
k_ipad = Fun_MD5(StrXor(password, ipad) + data);

k_opad = StrXor(password, opad);

byte[] Test = HexStringToArray(k_ipad);
temp = string.Empty;

char[] b = Encoding.GetEncoding(1252).GetChars(Test);
for (int i = 0; i < b.Length; i++)
{
temp += b[i];
}
temp = k_opad + temp;
return Fun_MD5(temp).ToLower();
}
}
}


你还可以参考
http://topic.csdn.net/u/20100928/14/642aaf0f-5058-4bd3-95a3-a471451d0fac.html
DiscussQuestions 2011-06-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sibang 的回复:]
你看看这篇文章
http://stackoverflow.com/questions/257462/c-to-php-base64-encode-decode
[/Quote]

谢谢,其实我重点是想知道hash_hmac函数怎么用C#翻译过来
www_7di_net 2011-06-01
  • 打赏
  • 举报
回复
你看看这篇文章
http://stackoverflow.com/questions/257462/c-to-php-base64-encode-decode

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧