目前,我正在使用iOS安全框架生成一个RSAKeyPair
statusCode = SecKeyGeneratePair(keyPairAttributes as CFDictionary, &newPublicKey, &newPrivateKey)然后,我想用PKCS8将这些密钥导出为PEM格式。苹果提供的导出密钥的标准方法是:
let cfData = SecKeyCopyExternalRepresentation(self, &error)但是这个数据给了我PKCS1格式的密钥。有没有办法把PKCS1格式转换成PKCS8格式?
到目前为止,我的所有研究都让我对如何转换这些格式一无所知。
发布于 2018-03-27 01:31:46
我不能翻译成Swift,但这是近乎客观的C:
SecItemImportExportKeyParameters keyParams = {};
keyParams.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
keyParams.passphrase = you_need_a_cfstringref_here;
SecExternalFormat dataFormat = kSecFormatWrappedPKCS8;
OSStatus status = SecItemExport(privateKey, dataFormat, 0, &keyParams, &cfData);https://stackoverflow.com/questions/49465096
复制相似问题