Http URL: https://raw.github.com/square/okhttp/master/README.md To find SHA1SUM from my system: Manually getting the response from the postman url and placing the response in a file and then Using the following command (linux)
sha1sum filename
From android code: After getting the http sync call response,passing that string to the following method.
public static String SHA1(String text) {
Log.d("SHA1:::", ":" + text);
try {
MessageDigest md;
md = MessageDigest.getInstance("SHA-1");
md.update(text.getBytes("iso-8859-1"),
0, text.length());
byte[] sha1hash = md.digest();
System.out.println(("SHA1:::::" + sha1hash));
System.out.println(toHex(sha1hash));
return toHex(sha1hash);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
private final static String HEX = "0123456789ABCDEF";
public static String toHex(byte[] buf) {
if (buf == null) return "";
int l = buf.length;
StringBuffer result = new StringBuffer(2 * l);
for (int i = 0; i < buf.length; i++) {
appendHex(result, buf[i]);
}
return result.toString();
}
But i am getting different results from code and manual sha1sum.Please suggest me how can i do this..
The code is correct which i posted in the question.The sha1sum of the android code is correct where as the manual sha1sum is wrong.I taken the response of the URL from the mozilla web browser,the browser truncates the last white lines.. so the sha1sum is incorrect.Now i am using the Chrome for response thing,sha1sum is same as the android code sha1sum.
Note:Please use the chrome response so that we can get the same sha1sum..