[英]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.