-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShaMethod.java
More file actions
executable file
·33 lines (29 loc) · 892 Bytes
/
ShaMethod.java
File metadata and controls
executable file
·33 lines (29 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.killmalware.bbsec;
import java.io.UnsupportedEncodingException;
import net.rim.device.api.crypto.SHA1Digest;
public class ShaMethod {
public static String sha(final String msg)
{
SHA1Digest sha1Digest = new SHA1Digest();
String sha = msg;
byte[] inpData = null;
try {
inpData = sha.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
sha1Digest.update(inpData, 0, inpData.length);
byte[] digest = sha1Digest.getDigest();
StringBuffer shaRes = new StringBuffer(40); //40 hex char is size of 160-bit SHA-1 result
for (int a = 0; a < digest.length; a++)
{
String tmp = Integer.toHexString(0xff & digest[a]);
if(tmp.length() == 1) //If hex value is "0X" then tmp is just one digit "X"
{
shaRes.append('0');
}
shaRes.append(tmp);
}
return shaRes.toString();
}
}