热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

生成无法导出的私钥-Generateprivatekeythatcannotbeexported

IwanttogenerateakeypaironaniPhonesuchthattheprivatekeycanonlyeverbeusedtosignb

I want to generate a key pair on an iPhone such that the private key can only ever be used to sign blocks of data on that particular iPhone.

我想在iPhone上生成密钥对,这样私钥就只能用于在特定iPhone上签署数据块。

The SecKeyGeneratePair function looks promising. I can generate a key pair to the keychain (using kSecAttrIsPermanent) and I can disable decryption, derivation and unwrapping with the private key (setting kSecAttrCanDecrypt, kSecAttrCanDerive and kSecAttrCanUnwrap to false).

SecKeyGeneratePair函数看起来很有前途。我可以为钥匙串生成密钥对(使用kSecAttrIsPermanent),我可以使用私钥禁用解密,派生和解包(将kSecAttrCanDecrypt,kSecAttrCanDerive和kSecAttrCanUnwrap设置为false)。

Two things worry me about key pairs generated with SecKeyGeneratePair:

有两件事让我担心使用SecKeyGeneratePair生成的密钥对:

  1. Is it possible to export the private key outside of the keychain into application memory?

    是否可以将钥匙串外的私钥导出到应用程序内存中?

  2. Is it possible to change a key property (e.g. set kSecAttrCanDecrypt to true) after a private key has been created?

    是否可以在创建私钥后更改密钥属性(例如,将kSecAttrCanDecrypt设置为true)?

2 个解决方案

#1


5  

This article provides more details (compared to other answers in this thread):

本文提供了更多详细信息(与此主题中的其他答案相比):

SecGenerateKeyPair(), which is used to generate RSA and ECDSA key pairs, can now be configured to directly store the generated private key in the device’s Keychain (within the Secure Enclave). This means that the private key can be used without ever leaving the device’s Secure Enclave.

SecGenerateKeyPair()用于生成RSA和ECDSA密钥对,现在可以配置为将生成的私钥直接存储在设备的Keychain中(在Secure Enclave中)。这意味着可以在不离开设备的Secure Enclave的情况下使用私钥。

And the important addition:

而重要的补充:

The kSecAttrTokenIDSecureEnclave attribute needs to be used when generating the key pair.

生成密钥对时需要使用kSecAttrTokenIDSecureEnclave属性。

If you don't specify this attribute the private key will be accessible even on iOS9.

如果您未指定此属性,即使在iOS9上也可以访问私钥。

#2


4  

To answer the first question, the private key cannot be retrieved according to this source:

要回答第一个问题,根据此来源无法检索私钥:

One API call, SecKeyGeneratePair(), creates a public and private key. The public key is returned to the app, and the private key is sent directly to the Secure Enclave. This private key cannot be retrieved.

一个API调用SecKeyGeneratePair()创建公钥和私钥。公钥将返回到应用程序,私钥将直接发送到Secure Enclave。无法检索此私钥。

More information is available here:

更多信息请点击这里:

The supported keys are Elliptic Curve P256, the private key is not extractible in any form, even protected, and the applications are RawSign and RawVerify.

支持的键是Elliptic Curve P256,私钥不能以任何形式提取,甚至受保护,应用程序是RawSign和RawVerify。


推荐阅读
author-avatar
Kanxsg
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有