Skip to content

Instantly share code, notes, and snippets.

@kean kean/NukeDemo-Bridging-Header.h Secret
Created Apr 24, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.