美文网首页
hmacSha1算法

hmacSha1算法

作者: Smallwolf_JS | 来源:发表于2020-09-15 22:01 被阅读0次
    • (NSString ) hmacSha1:(NSString)key text:(NSString*)text
      {
      const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
      const char *cData = [text cStringUsingEncoding:NSUTF8StringEncoding];

      uint8_t cHMAC[CC_SHA1_DIGEST_LENGTH];

      CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);

      //NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:CC_SHA1_DIGEST_LENGTH];
      NSString hash;
      NSMutableString
      output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
      for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
      [output appendFormat:@"%02x", cHMAC[i]];
      hash = output;

      return hash;
      }

    相关文章

      网友评论

          本文标题:hmacSha1算法

          本文链接:https://www.haomeiwen.com/subject/edjqyktx.html