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
ios objective-c rsa


source to share


No one has answered this question yet

See similar questions:

five
SecKeyGetBlockSize or SecKeyRawVerify to reset the public key EXC_BAD_ACCESS code = 2
1
NSString for SecKeyRef

or similar:

1244
How can I sort NSMutableArray with custom objects in it?
1180
How can I check if a string contains another string in Objective-C?
1066
Shortcuts in Objective-C to combine NSStrings
883
How can I convert an NSString value to NSData?
818
Calculate RSA key fingerprint
555
Convert UTF-8 encoded NSData to NSString
524
How to convert NSString to NSNumber
300
Converting NSURL to NSString
five
Why does SecKeyEncrypt return paramErr (-50) for input lines larger than 246 bytes?
0
How do I check the receipt of an in-app purchase?



All Articles
Loading...
X
Show
Funny
Dev
Pics