Skip to content

Instantly share code, notes, and snippets.

@kean
Created April 24, 2018 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kean/f5e1975e01d5e0c8024bc35556665d7b to your computer and use it in GitHub Desktop.
Save kean/f5e1975e01d5e0c8024bc35556665d7b to your computer and use it in GitHub Desktop.
SHA1
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "SHA1.h"
// The MIT License (MIT)
//
// Copyright (c) 2015-2018 Alexander Grebenyuk (github.com/kean).
#import <Foundation/Foundation.h>
/// Produces 160-bit hash value using SHA-1 algorithm.
/// - returns: String containing 160-bit hash value expressed as a 40 digit
/// hexadecimal number.
extern NSString *
_nuke_sha1(const char *data, uint32_t length);
// The MIT License (MIT)
//
// Copyright (c) 2015-2018 Alexander Grebenyuk (github.com/kean).
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonCrypto.h>
NSString *
_nuke_sha1(const char *data, uint32_t length) {
unsigned char hash[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data, (CC_LONG)length, hash);
char utf8[2 * CC_SHA1_DIGEST_LENGTH + 1];
char *temp = utf8;
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
snprintf(temp, 3, "%02x", hash[i]);
temp += 2;
}
return [NSString stringWithUTF8String:utf8];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment