swift - RSA Key 似乎只包含它的内存地址。斯威夫特,MacOS
问题描述
我目前正在尝试为 Mac 应用程序生成 CSR,并缩小了我的密钥生成范围内的问题。
我目前正在使用下面的代码来生成密钥,这在大多数情况下都有效。但是,从我一直使用的许多参考资料来看,预期的输出应该是:
<SecKeyRef算法id:1,密钥类型:RSAPrivateKey,版本:4,块大小:2048位,地址:0x600001ae74c0>
但是,在生成密钥后在调试中检查 SecKeyRef 输出时,我得到的只是:
<SecKeyRef: 0x600000cbd6e0>
我怀疑这就是我在 Red Kestrel 上检查 CSR 时发现密钥大小为 0 并且无法读取 CSR 签名的原因。
只是想知道这是否可能是为什么?
let publicKeyParameters: [String: Any] = [
String(kSecAttrIsPermanent): true,
String(kSecAttrAccessible): kSecAttrAccessibleAfterFirstUnlock,
String(kSecAttrApplicationTag): tagPublic.data(using: .utf8)!
]
let privateKeyParameters: [String: Any] = [
String(kSecAttrIsPermanent): true,
String(kSecAttrAccessible): kSecAttrAccessibleAfterFirstUnlock,
String(kSecAttrKeySizeInBits): 2048,
String(kSecAttrApplicationTag): tagPrivate.data(using: .utf8)!
]
let parameters: [String: Any] = [
String(kSecAttrKeyType): algorithm.secKeyAttrType,
String(kSecAttrKeySizeInBits): keySize,
String(kSecReturnRef): true,
String(kSecPublicKeyAttrs): publicKeyParameters,
String(kSecPrivateKeyAttrs): privateKeyParameters
]
var error: Unmanaged<CFError>?
let privateKey = SecKeyCreateRandomKey(parameters as CFDictionary, &error)
解决方案
推荐阅读
- javascript - 使用纯 JS 的 REST API 微调器
- android - RelativeLayout.LayoutParams 不会正确设置宽度android
- matlab - 将 Matlab 中由相同整数索引的矩阵的列求和
- javascript - 加载画布时精灵不出现
- ios - 当从视图 A 切换到视图 B 时,A 的视图控制器会发生什么?
- ruby-on-rails - byebug 在我输入时没有显示输出
- ruby-on-rails - Ruby on Rails - “原因:找不到图像”
- javascript - 即使系统设置不正确,如何在 JavaScript 中找到正确的时区?
- reactjs - 提供反应网页的替代方式
- python - SymPy 中 1/x 的集成