Convert NSString to SecKeyRef for RSA to Objective-C validation
I want to check data on iOS 7. Now I have a function:
-(BOOL) PKCSVerifyBytesSHA256withRSA:(NSData*) plainData
withSign:(NSData*) signature
withKey:(SecKeyRef) public_Key{
size_t signedHashBytesSize = SecKeyGetBlockSize(public_Key);
const void* signedHashBytes = [signature bytes];
size_t hashBytesSize = CC_SHA256_DIGEST_LENGTH;
uint8_t* hashBytes = malloc(hashBytesSize);
if (!CC_SHA256([plainData bytes], (CC_LONG)[plainData length], hashBytes)){
return nil;
}
OSStatus status = SecKeyRawVerify(publicKey,
kSecPaddingPKCS1SHA256,
hashBytes,
hashBytesSize,
signedHashBytes,
signedHashBytesSize);
return status == errSecSuccess;
}
and the key:
NSString *public_key = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCT2eIq8i/uAHzvwOWhFU9AuRHjPnGq8wD461ZH7N4/LjoRwPaPF3meyyENJgtDr4EyhV9KN77/3VT+87ZpT6QH9w6Q5XwDmM3jhU6bUhWyIPLzrd5XE2rQKRIMXixflz/8Q327VHKsLoKu44HuCh6XrB+uMWUjwVLCLOi2U0sYdQIDAQAB";
I suggested a link here
so I add - (SecKeyRef)getPublicKeyRef
both PKCSVerifyBytesSHA256withRSA
to the new class and call
RSA1 * rsa1 = [[RSA1 alloc] init]; if ([rsa1 PKCSVerifyBytesSHA256withRSA: Ddata withSign: Dsig withKey: [rsa1 getPublicKeyRef]]) { NSLog (@ "True");} else { NSLog (@ "nil");}
but i got an error on the line
size_t signedHashBytesSize = SecKeyGetBlockSize (public_Key);in a function
PKCSVerifyBytesSHA256withRSA
with a note:
Thread 1: EXC_BAD_ACCESS(code=1, address=0x10)
Is there a way to solve these problems?
+3
source to share
No one has answered this question yet
See similar questions:
or similar: