Tanddd Tanddd - 1 year ago 78
Objective-C Question

How to create openssh keys on iOS via OC code

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.

Answer Source

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);


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.

For information on using OpenSSL libraries within your project, see: https://github.com/krzyzanowskim/OpenSSL

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download