Initialize Public Key From Modulus & Exponent using OpenSSL

前端 未结 1 1633
我在风中等你
我在风中等你 2020-12-16 07:17

Trying to generate an RSA Public Key given an APIs modulus and exponent. I\'m using OpenSSL on iOS 4.2.

Generating the public key manually is an option (see below) h

相关标签:
1条回答
  • 2020-12-16 07:31

    To do this make sure you have the OpenSSL library linked (instructions here http://code.google.com/p/ios-static-libraries/)

    Once linked you'll have access to several BIGNUM converters. I turned the modulus into hex using the BN_hex2bn method saving the hex string into 'exponent'

    Then create the BIGNUM struct and encrypt using RSA_public_encrypt

    RSA *rsa = NULL;
    
    rsa->n = BN_new();
    BN_copy(rsa->n,modulus);   
    rsa->e = BN_new();
    BN_copy(rsa->e,exponent);     
    rsa->iqmp=NULL;
    rsa->d=NULL;
    rsa->p=NULL;
    rsa->q=NULL;
    

    Good Luck!

    0 讨论(0)
提交回复
热议问题