现在我的公钥有问题,我使用 SecKeyGeneratePair 生成公钥和私钥。现在我必须将我的公钥发送到服务器。我使用下面的方法将 SecKeyRef 转换为 NSData,我总是得到相同的公钥。但是我将其转换为base64格式并将其发送到服务器。但它根本不起作用,服务器(Java)开始抛出错误。这是我的 iOS 代码:
- (NSData *)getPublicKeyBits {
OSStatus sanityCheck = noErr;
NSData * publicKeyBits = nil;
NSMutableDictionary * queryPublicKey = [[NSMutableDictionary alloc] init];
// Set the public key query dictionary.
[queryPublicKey setObject:(id)kSecClassKey forKey:(id)kSecClass];
[queryPublicKey setObject:publicTag forKey:(id)kSecAttrApplicationTag];
[queryPublicKey setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType];
[queryPublicKey setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnData];
// Get the key bits.
sanityCheck = SecItemCopyMatching((CFDictionaryRef)queryPublicKey, (CFTypeRef *)&publicKeyBits);
if (sanityCheck != noErr)
{
publicKeyBits = nil;
}
[queryPublicKey release];
return publicKeyBits;
}
谁能帮我将 SecKeyRef 转换为 NSString 或 NSData。
提前致谢!!!
——穆拉利克里希南