我正在使用数字证书在我的应用程序中签署数据文件。当对SecKeyRawVerify
的调用返回-9809时,下面的代码片段失败。这是在iPhone上运行。我什至不能确切地确定这个错误代码意味着什么SecKeyRawVerify和OSError -9809
以前的安全框架调用来加载和创建SecTrustRef从中获取公共密钥似乎很好 - 没有错误。唯一的问题是SecTrustEvaluate
的电话会返回kSecTrustResultUnspecified
,但我认为这是因为我使用的策略是由SecPolicyCreateBasicX509
呼叫返回的样板文件。
任何帮助或见解将非常感激。
由于
SecKeyRef keyRef = SecTrustCopyPublicKey (trustRef);
fileURL = [[NSBundle mainBundle] URLForResource:@"data" withExtension:@"txt"];
NSData *data = [NSData dataWithContentsOfURL:fileURL];
fileURL = [[NSBundle mainBundle] URLForResource:@"data" withExtension:@"sgn"];
NSData *signature = [NSData dataWithContentsOfURL:fileURL];
NSLog(@"Hash block size = %zu",SecKeyGetBlockSize(keyRef));
status = SecKeyRawVerify (keyRef,
kSecPaddingPKCS1SHA1,
(const uint8_t *)[data bytes],
(size_t)[data length],
(const uint8_t *)[signature bytes],
(size_t)[signature length]
);
并不是说SecKeyRawVerify预计数据的散列。这就是说,无论您用什么来生成签名,首先都会根据数据的散列创建签名。 – Greg