我正在尝试在iOS上生成OpenSSH密钥对。我现在坚持如何从PEM创建/提取公共ssh-RSA密钥,相当于:
ssh-keygen -y -f ~/.ssh/private
这就是我创建私钥的方式,它似乎创建了一个有效的密钥对。
const int kBits = 1024;
const int kExp = 3;
int keylen;
int pub_len;
char *pem_key;
RSA *rsa = RSA_generate_key(kBits, kExp, 0, 0);
BIO *bio = BIO_new(BIO_s_mem());
PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, NULL);
keylen = BIO_pending(bio);
pem_key = calloc(keylen+1, 1); /* Null-terminate */
BIO_read(bio, pem_key, keylen);
printf("%s", pem_key);
BIO_free_all(bio);
RSA_free(rsa);
free(pem_key);
我是密码学和C的新手,任何提示或线索都非常感激。提前谢谢!