简体   繁体   English

如何获取在 iOS Keychain 中创建和存储的密钥的唯一标识符

[英]How to get a unique identifier of a key created and stored in iOS Keychain

When I create a new key in Keychain using SecKeyCreateRandomKey I would like to get UUID of this key (or any other unique id ) and use this id to search for this key in Keychain in the future.当我使用SecKeyCreateRandomKey在 Keychain 中创建一个新密钥时,我想获取此密钥的UUID (或任何其他唯一id )并使用此id将来在 Keychain 中搜索此密钥。 How can I do it?我该怎么做?

So far I managed only to provide kSecAttrApplicationTag as an attribute for future queries, but this solution is problematic as there can be any amount of keys created with this tag.到目前为止,我只设法提供kSecAttrApplicationTag作为未来查询的属性,但此解决方案存在问题,因为可以使用此标记创建任意数量的密钥。

When looking at how keys are stored in Keychain database I see there is a UUID field there, though I cannot find a way to access it at the application level.在查看密钥如何存储在钥匙串数据库中时,我看到那里有一个UUID字段,但我找不到在应用程序级别访问它的方法。

在此处输入图像描述

I have used the keychain third library for this,If you feel comfortable check this out, I think it's easy and the best for your scenario.为此,我使用了钥匙串第三个库,如果您觉得方便,请检查一下,我认为它很简单,而且最适合您的场景。 https://github.com/evgenyneu/keychain-swift https://github.com/evgenyneu/keychain-swift

You could use kSecAttrApplicationTag to store a custom scheme with unique UID that you can generate independently.您可以使用kSecAttrApplicationTag来存储具有您可以独立生成的唯一 UID 的自定义方案。

Example:例子:

kSecAttrApplicationTag -> {COMMON_ATTRIBUTE_PART}-{YOUR_GENERATED_UID}

Therefore you can store your generated UID and knowing the COMMON_ATTRIBUTE_PART you can later search for the key.因此,您可以存储生成的 UID 并知道 COMMON_ATTRIBUTE_PART 以后可以搜索密钥。 That way you don't have to rely on UUID generated by keychain.这样你就不必依赖钥匙串生成的 UUID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从存储在iOS钥匙串中的密钥获取DER格式的公钥? - How to get public key in DER format from key stored in iOS keychain? 如何在IOS上获取应用程序的唯一标识符 - How to get the unique identifier of an application on IOS 获取iOS中信标的唯一标识符? - Get unique identifier for beacon in iOS? ios钥匙串中的公钥在每次获取时都会发生变化 - public key in ios keychain changes on each get iOS:如何获取事件的标识符,该事件的标识符是通过调用EKEventEditViewController创建的 - iOS: How to get the identifier of an event, which was created via a call to EKEventEditViewController 如何在iPhone中获取唯一标识符 - How to get unique identifier in iphone 如何在具有唯一密钥的Keychain类中存储多个密码? - How to store multiple passwords in Keychain class with unique Key? iOS钥匙串和加密密钥,如何确保安全直到存储 - iOS keychain and encryption keys, how to keep safe until stored 如何使用iOS钥匙串在iPhone上存储OAuth令牌? - How to use iOS Keychain to stored an OAuth token on iPhone? 如何获取在Firebase中添加子项而创建的唯一密钥? - how to get the unique key that was created adding a child in firebase?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM