求将以下c#代码转换为java代码
publicstringComputeSignature(stringsignatureBase,stringconsumerSecret,stringtokenSecr...
public string ComputeSignature(string signatureBase, string consumerSecret, string tokenSecret){
string sign = FormsAuthentication.HashPasswordForStoringInConfigFile(""+signatureBase+"", "MD5").ToLower();
string key = string.Format("{0}&{1}&{2}",
Encoding.ASCII.GetString(EncodeToBytes(consumerSecret, Encoding.UTF8)),
sign,
Encoding.ASCII.GetString(EncodeToBytes(tokenSecret, Encoding.UTF8)));
returnConvert.ToBase64String(Encoding.ASCII.GetBytes(key));
}
private static byte[] EncodeToBytes(string input, Encoding enc){
if (string.IsNullOrEmpty(input))
returnnewbyte[0];
byte[] inbytes = enc.GetBytes(input);
int unsafeChars = 0;
char c;
foreach (byte b in inbytes){
c = (char)b;
if (NeedsEscaping(c))
unsafeChars++;
}
if (unsafeChars == 0)
return inbytes;
byte[] outbytes = newbyte[inbytes.Length + (unsafeChars * 2)];
int pos = 0;
for (int i = 0; i < inbytes.Length; i++){
byte b = inbytes[i];
if (NeedsEscaping((char)b)){
outbytes[pos++] = (byte)'%';
outbytes[pos++] = (byte)IntToHex((b >> 4) & 0xf);
outbytes[pos++] = (byte)IntToHex(b & 0x0f);
}else
outbytes[pos++] = b;
}
return outbytes;
} 展开
string sign = FormsAuthentication.HashPasswordForStoringInConfigFile(""+signatureBase+"", "MD5").ToLower();
string key = string.Format("{0}&{1}&{2}",
Encoding.ASCII.GetString(EncodeToBytes(consumerSecret, Encoding.UTF8)),
sign,
Encoding.ASCII.GetString(EncodeToBytes(tokenSecret, Encoding.UTF8)));
returnConvert.ToBase64String(Encoding.ASCII.GetBytes(key));
}
private static byte[] EncodeToBytes(string input, Encoding enc){
if (string.IsNullOrEmpty(input))
returnnewbyte[0];
byte[] inbytes = enc.GetBytes(input);
int unsafeChars = 0;
char c;
foreach (byte b in inbytes){
c = (char)b;
if (NeedsEscaping(c))
unsafeChars++;
}
if (unsafeChars == 0)
return inbytes;
byte[] outbytes = newbyte[inbytes.Length + (unsafeChars * 2)];
int pos = 0;
for (int i = 0; i < inbytes.Length; i++){
byte b = inbytes[i];
if (NeedsEscaping((char)b)){
outbytes[pos++] = (byte)'%';
outbytes[pos++] = (byte)IntToHex((b >> 4) & 0xf);
outbytes[pos++] = (byte)IntToHex(b & 0x0f);
}else
outbytes[pos++] = b;
}
return outbytes;
} 展开
1个回答
2017-02-20
展开全部
不如百度 C# MD5
其实,C#中MD5更容易的
~
其实,C#中MD5更容易的
~
追问
谢谢你回答我的问题 不过现在是要求我写一段等效的java代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询