Last active
December 22, 2015 20:29
-
-
Save lkdocs/6526902 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
+ (NSData *)getSignatureBytes:(NSData *)plainText withPrivateKey:(SecKeyRef)privateKey | |
{ | |
OSStatus sanityCheck = noErr; | |
NSData * signedHash = nil; | |
uint8_t *signedHashBytesSize = SecKeyGetBlockSize(privateKey); | |
size_t signedHashBytes = malloc( signedHashBytesSize * sizeof(uint8_t) ); | |
memset((void *)signedHashBytes, 0x0, signedHashBytesSize); | |
sanityCheck = SecKeyRawSign(privateKey, | |
kSecPaddingPKCS1SHA256, | |
(const uint8_t *)[[self getHash256Bytes:plainText] bytes], | |
CC_SHA256_DIGEST_LENGTH, | |
(uint8_t *)signedHashBytes, | |
&signedHashBytesSize); | |
signedHash = [NSData dataWithBytes:(const void *)signedHashBytes length:(NSUInteger)signedHashBytesSize]; | |
if (signedHashBytes) free(signedHashBytes); | |
return signedHash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does
getHash256Bytes:
?