Tag: rsa

将NSData转换为SecKeyRef

我有一个公共密钥,我从远程服务器收集,我想用该公钥进行RSAencryption。 但问题是我得到公钥数据缓冲区中的字节数组。 我可以将其转换为NSData,但我不能转换为SecKeyRef,所以我可以继续encryption。 我的encryption代码是这样的: +(NSString *)encryptRSA:(NSString *)plainTextString withKey:(SecKeyRef)publicKey { size_t cipherBufferSize = SecKeyGetBlockSize(publicKey); uint8_t *cipherBuffer = malloc(cipherBufferSize); uint8_t *nonce = (uint8_t *)[plainTextString UTF8String]; SecKeyEncrypt(publicKey, kSecPaddingOAEP, nonce, strlen( (char*)nonce ), &cipherBuffer[0], &cipherBufferSize); NSData *encryptedData = [NSData dataWithBytes:cipherBuffer length:cipherBufferSize]; return [encryptedData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; } 正如你所看到的,我需要SecKeyRef对象types来完成我的encryption。 但是我的RSA公钥在NSDatavariables中。 那么如何将NSData转换为SecKeyRef对象types。 提前致谢。

将私钥添加到证书中,反之亦然

问题是,我想创build一个新的私人/公共密钥对新的应用程序。 所以我跟着文档( http://developer.apple.com/ios/manage/certificates/team/howto.action ),它说,首先创build一个新的密钥对。 好吧,我得到了一个证书签名请求文件,我必须上传到开发者主页(证书>开发)。 在那里,我发现,(因为)我们已经在appstore中有一个应用程序,已经有一个证书。 所以我下载了现有的并在查找器中双击它。 钥匙串已打开,但没有将证书附加到新创build的私钥(正如我所阐述的那样)。 我做错了什么? 我必须做什么来激活这个密钥对? 有人可以帮我解决这个问题吗? 感谢Br Nic

iOS SecKeyRef到NSData

我有两个公钥和私钥,都存储在SecKeyRefvariables中。 为了简单起见,让我们从公开的一个开始。 我想要做的是将其导出到一个NSData对象。 为此,苹果公司提供了一个几乎是着名的代码片段,在这里: – (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 […]