-
-
Save NghiaTranUIT/6cee45d5e9a1c347ea54 to your computer and use it in GitHub Desktop.
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
NSString *secret = @"xxx"; | |
NSString *data = @"http://someurl?someparams"; | |
const char *cKey = [secret cStringUsingEncoding:NSASCIIStringEncoding]; | |
const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding]; | |
unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH]; | |
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC); | |
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; | |
NSString *signature = [HMAC base64EncodedStringWithOptions:0]; |
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
secret = "xxx" | |
data = "http://someurl?someparams" | |
hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret.encode("ASCII"), data.encode("ASCII")) | |
signature = Base64.encode64(hmac).chomp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment