Ben feryat C# kodu eşit bir android MD5 hash dize oluşturmak için çalışıyorum:Android: HMAC MD5 dizesi nasıl oluşturulur?
:private string CalculateHMACMd5(string message, string key)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(key);
HMACMD5 hmacmd5 = new HMACMD5(keyByte);
byte[] messageBytes = encoding.GetBytes(message);
byte[] hashmessage = hmacmd5.ComputeHash(messageBytes);
string HMACMd5Value = ByteToString(hashmessage);
return HMACMd5Value;
}
private static string ByteToString(byte[] buff)
{
string sbinary = "";
for (int i = 0; i < buff.Length; i++)
{
sbinary += buff[i].ToString("X2");
}
return (sbinary);
}
Android kod Şu anda [ aynı C# kodu üretme değil] kullandığını
public static String sStringToHMACMD5(String sData, String sKey)
{
SecretKeySpec key;
byte[] bytes;
String sEncodedString = null;
try
{
key = new SecretKeySpec((sKey).getBytes(), "ASCII");
Mac mac = Mac.getInstance("HMACMD5");
mac.init(key);
mac.update(sData.getBytes());
bytes = mac.doFinal(sData.getBytes());
StringBuffer hash = new StringBuffer();
for (int i=0; i<bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
hash.append('0');
}
hash.append(hex);
}
sEncodedString = hash.
return sEncodedString;
}
Şimdiden teşekkürler.
android kodunu kontrol edin. – Basbous
[Muhtemelen Android HMAC MD5 Nasıl Üretilir?] Olası kopyası (http://stackoverflow.com/questions/3140650/how-to-generate-hmac-md5-in-android) – Thilo
@Thilo: Bağlantıyı kontrol ettim kendim sağladı, çözüm çalışmıyor. –