Advertisement
Advertisement
| 12.25.2007 at 11:20PM PST, ID: 23042815 |
|
[x]
Attachment Details
|
||
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: 34: |
// HMAC-SHA1 in JAVA
public static String getSHA1Digest(String PlainText, String key)
{
String sha_string = null;
try
{
SecretKey secretKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");
Mac messageAuthenticationCode = Mac.getInstance("HmacSHA1");
messageAuthenticationCode.init(secretKey);
messageAuthenticationCode.update(PlainText.getBytes());
byte[] digest = messageAuthenticationCode.doFinal();
sha_string = new String(HexBin.encode(digest));
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
return sha_string;
}
}
// HMAC-SHA1 in OpenSSL
void computeHmac(char* hmac, const char* input, int length, const char* key, int sizeKey)
{
unsigned int resultSize=0;
HMAC(EVP_sha1(),
key, sizeKey,
(const unsigned char*)(input), length,
(unsigned char*)(hmac), &resultSize);
assert(resultSize == 20);
}
|