Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save onlyyoujack/d490260fa05cb7f0e7e9 to your computer and use it in GitHub Desktop.
Save onlyyoujack/d490260fa05cb7f0e7e9 to your computer and use it in GitHub Desktop.

Revisions

  1. @septerr septerr revised this gist Feb 12, 2014. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  2. @septerr septerr revised this gist Feb 6, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions iOS
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    const char *cKey = [apiSecret cStringUsingEncoding:NSASCIIStringEncoding];
    const char *cData = [canonicalString cStringUsingEncoding:NSASCIIStringEncoding];
    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)];
  3. @septerr septerr created this gist Feb 6, 2014.
    4 changes: 4 additions & 0 deletions Rails
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    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
    6 changes: 6 additions & 0 deletions iOS
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    const char *cKey = [apiSecret cStringUsingEncoding:NSASCIIStringEncoding];
    const char *cData = [canonicalString 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];