gpt4 book ai didi

php - 如何使用 php 脚本生成的公钥加密 Objective-C 中的数据

转载 作者:行者123 更新时间:2023-12-03 17:51:31 25 4
gpt4 key购买 nike

我环顾四周,发现有关 Mac OS X 上加密的信息很少。似乎较新版本的 Mac OS X 中已弃用 OpenSSL 支持。我需要能够从 10.5 及更高版本开始提供支持。这是我的问题:

我使用 php 在我们的许可服务器上生成了公钥和私钥对(代码如下所示)

$dn = array(configs....);
$privkey = openssl_pkey_new();

$csr = openssl_csr_new($dn, $privkey);

$sscert = openssl_csr_sign($csr, null, $privkey, $term);

openssl_x509_export($sscert, $publickey);
openssl_pkey_export($privkey, $privatekey, "somepassphrase");

//base64 encode the keys
$privatekey = base64_encode($privatekey);
$publickey = base64_encode($publickey);

base64 编码的私钥存储在我们的一台服务器上的安全位置,base64 编码的公钥写入文件供用户下载。该文件被加载到用 cocoa 编写的 MacOS X 桌面应用程序中,该应用程序对公钥进行 base64 解码。直到这一步就好了。但是,我想用公钥加密数据并将其发送到我们的许可证服务器。有谁知道我如何使用这个公钥来加密 cocoa 中的数据以及什么是“最佳”实践方法?任何示例或提示将不胜感激!

最佳答案

在 Mac 上弃用的并不是 OpenSSL,而只是 OS X 提供的 OpenSSL 库被弃用。没有什么可以阻止您编译自己的 OpenSSL 并通过静态链接在您的应用程序中使用它:

Although OpenSSL is commonly used in the open source community, OpenSSL does not provide a stable API from version to version. For this reason, although OS X provides OpenSSL libraries, the OpenSSL libraries in OS X are deprecated, and OpenSSL has never been provided as part of iOS. Use of the OS X OpenSSL libraries by apps is strongly discouraged.

If your app depends on OpenSSL, you should compile OpenSSL yourself and statically link a known version of OpenSSL into your app. This use of OpenSSL is possible on both OS X and iOS. However, unless you are trying to maintain source compatibility with an existing open source project, you should generally use a different API.

Common Crypto and Security Transforms are the recommended alternatives for general encryption. CFNetwork and Secure Transport are the recommended alternatives for secure communications.

换句话说:在 OS X 应用程序中使用 OpenSSL 仍然没问题 - 只是不再依赖捆绑的 OpenSSL 即可。或者,您可以使用 OS X'Security Framework :它能够处理 X.509 公钥加密,您似乎也在这样做。

来源:Cocoa Cryptographic Services Guide

关于php - 如何使用 php 脚本生成的公钥加密 Objective-C 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25371892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com