我正在寻找一种使用Apple的安全工具从钥匙串中删除私钥的方法。在这种特定情况下,私钥还具有与其相关联的证书,它与之形成身份(证书+私钥),因此您可以单击“钥匙串访问”的“证书”部分,右键单击“导入的私钥”键”,然后单击“删除”:
据我所知,无法使用security
工具(参见https://ss64.com/osx/security.html)来执行此操作;可以删除的命令是
> security help | grep delete
delete-keychain Delete keychains and remove them from the search list.
delete-generic-password Delete a generic password item.
delete-internet-password Delete an internet password item.
delete-certificate Delete a certificate from a keychain.
delete-identity Delete an identity (certificate + private key) from a keychain.
delete-identity
还将删除证书。有什么方法可以通过编程方式实现与“钥匙串访问”命令相同的效果?
(我确实注意到Delete Private Key from Keychain和Delete Private key from keychain mac programmatically都引用了Swift和Objective-C解决方案,但我更喜欢使用Go或Apple命令行工具)。
答案 0 :(得分:0)
我最终使用security delete-identity
删除证书和私钥,然后使用security import
仅重新导入证书来进行此操作。