现在我的公钥有问题,我使用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;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我将SecKeyRef转换为NSString或NSData.
提前致谢!!!
-Murali Krishnan