如何通过Objective-C代码在iOS上创建openssh键 [英] How to create openssh keys on iOS via Objective-C code
问题描述
我们可以通过"ssh-keygen ..."命令获取openssh密钥,或者通过"openssl genrsa ..."命令获取openssl密钥.但是我可以通过Objective-C代码在我的iOS应用中执行此操作吗?任何帮助将不胜感激.
We can get openssh keys by order 'ssh-keygen...', or get openssl keys by order 'openssl genrsa...'. But can I do this in my iOS app via Objective-C code? Any help will be appreciated.
推荐答案
您将需要使用OpenSSL之类的库来生成密钥.这不是Objective-C,但是您可以与C库进行交互,因为Objective-C是超集.您将需要阅读文档以完全了解该库的工作原理,但这是一个简单的示例:
You'll need to use a library like OpenSSL to generate the keys. This isn't Objective-C, but you can interact with C libraries since Objective-C is a superset. You will need to read the documentation to fully understand how the library works, but this is a quick example:
RSA *myrsa;
unsigned long e = RSA_3;
BIO* out = NULL;
myrsa = RSA_generate_key(2048,e,NULL,NULL);
out=BIO_new(BIO_s_file());
if (myrsa == NULL) {
/* error handling here /*
}
您将需要将密钥数据写到某个地方.如果没有更具体的示例说明您的工作,这就是我所能提供的最好的.
You will want to write the key data out somewhere. Without a more specific example of what you are doing, this is the best I can offer.
有关在项目中使用OpenSSL库的信息,请参见: https://github.com/krzyzanowskim/OpenSSL
For information on using OpenSSL libraries within your project, see: https://github.com/krzyzanowskim/OpenSSL
这篇关于如何通过Objective-C代码在iOS上创建openssh键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!