我想验证iOS 7上的数据。现在我有一个功能:
-(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;
}
和一把钥匙:
NSString *public_key = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCT2eIq8i/uAHzvwOWhFU9AuRHjPnGq8wD461ZH7N4/LjoRwPaPF3meyyENJgtDr4EyhV9KN77/3VT+87ZpT6QH9w6Q5XwDmM3jhU6bUhWyIPLzrd5XE2rQKRIMXixflz/8Q327VHKsLoKu44HuCh6XrB+uMWUjwVLCLOi2U0sYdQIDAQAB";
我建议使用链接here
所以我将- (SecKeyRef)getPublicKeyRef
和PKCSVerifyBytesSHA256withRSA
添加到新类并调用
RSA1 *rsa1 =[[RSA1 alloc]init]; if([rsa1 PKCSVerifyBytesSHA256withRSA:Ddata withSign:Dsig withKey:[rsa1 getPublicKeyRef]]){ NSLog(@"True");} else{ NSLog(@"nil");}
但我收到了错误
size_t signedHashBytesSize = SecKeyGetBlockSize(public_Key);在
PKCSVerifyBytesSHA256withRSA
函数中,附注:Thread 1: EXC_BAD_ACCESS(code=1, address=0x10)
有什么方法可以解决这个问题吗?