Skip to content

Instantly share code, notes, and snippets.

@lkdocs
Last active December 22, 2015 20:29
Show Gist options
  • Save lkdocs/6526902 to your computer and use it in GitHub Desktop.
Save lkdocs/6526902 to your computer and use it in GitHub Desktop.
+ (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;
}
@hohl
Copy link

hohl commented Feb 4, 2014

What does getHash256Bytes:?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment