Created
December 11, 2008 20:12
-
-
Save adambair/34854 to your computer and use it in GitHub Desktop.
Needed to convert this java method to Objective-C. It turnes out that it's only doing starndard HmacSHA1. Don't ask how long it took me to figure it out.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.crypto.Mac; | |
import javax.crypto.spec.SecretKeySpec; | |
public static String someHashMethod(String data, String hash) { | |
byte[] hashBytes = hash.getBytes(); | |
SecretKeySpec signKey = new SecretKeySpec(hashBytes, "HmacSHA1"); | |
Mac mac = Mac.getInstance("HmacSHA1"); | |
mac.init(signKey); | |
byte[] rawHmac = mac.doFinal(data.getBytes()); | |
BigInteger number = new BigInteger(1, rawHmac); | |
String returnHash = number.toString(16); | |
if (returnHash.length() == 39) { | |
returnHash = "0" + returnHash; | |
} | |
return returnHash; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "GHNSString+HMAC.h" | |
[payload gh_hmacSha1:hashKey]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment