[AC-1906] md5 checksum for blobs on Android broken
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-03-20T16:03:42.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | n/a |
Reporter | Johan Lundin |
Assignee | Daniel Sefton |
Created | 2012-08-30T13:54:34.000+0000 |
Updated | 2016-03-08T07:40:49.000+0000 |
Description
The implementation of md5 checksum for Android is broken for binary blobs.
In https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/utils/src/java/ti/modules/titanium/utils/UtilsModule.java the method
public String md5HexDigest(Object obj)
{
String data = convertToString(obj);
if (data != null) {
return DigestUtils.md5Hex(data);
}
return null;
}
is incorrect since converting a blob to a string before computing md5 on it gives incorrect md5 checksums. The correct implementation should be
public String md5HexDigest(Object obj)
{
if (obj instanceof String) {
return DigestUtils.md5Hex((String)obj);
} else if (obj instanceof TiBlob) {
return DigestUtils.md5Hex(((TiBlob) obj).getBytes());
}
return null;
}
Fixed in master: https://github.com/appcelerator/titanium_mobile/commit/affe0d6fe188bf7aa58e0a08319a057ba36ad226#android/modules/utils/src/java/ti/modules/titanium/utils/UtilsModule.java