mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
fix crash figuring md5sum of null bytes
Just return null String
This commit is contained in:
parent
89ec7987e6
commit
019cc628e4
1 changed files with 20 additions and 16 deletions
|
@ -133,24 +133,28 @@ public class JNIUtilsImpl implements JNIUtils {
|
|||
|
||||
public String getMD5SumFor( byte[] bytes )
|
||||
{
|
||||
byte[] digest = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] buf = new byte[128];
|
||||
int nLeft = bytes.length;
|
||||
int offset = 0;
|
||||
while ( 0 < nLeft ) {
|
||||
int len = Math.min( buf.length, nLeft );
|
||||
System.arraycopy( bytes, offset, buf, 0, len );
|
||||
md.update( buf, 0, len );
|
||||
nLeft -= len;
|
||||
offset += len;
|
||||
String result = null;
|
||||
if ( bytes != null ) {
|
||||
byte[] digest = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] buf = new byte[128];
|
||||
int nLeft = bytes.length;
|
||||
int offset = 0;
|
||||
while ( 0 < nLeft ) {
|
||||
int len = Math.min( buf.length, nLeft );
|
||||
System.arraycopy( bytes, offset, buf, 0, len );
|
||||
md.update( buf, 0, len );
|
||||
nLeft -= len;
|
||||
offset += len;
|
||||
}
|
||||
digest = md.digest();
|
||||
} catch ( java.security.NoSuchAlgorithmException nsae ) {
|
||||
Log.ex( TAG, nsae );
|
||||
}
|
||||
digest = md.digest();
|
||||
} catch ( java.security.NoSuchAlgorithmException nsae ) {
|
||||
Log.ex( TAG, nsae );
|
||||
result = Utils.digestToString( digest );
|
||||
}
|
||||
return Utils.digestToString( digest );
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getMD5SumFor( String dictName, byte[] bytes )
|
||||
|
|
Loading…
Add table
Reference in a new issue