I'm looking to generate a rsa public key (pem) from both the modulus and exponent in Objective-C. This function can be done in Java by the following;
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, exponent));
Although I'm having some trouble writing this for the iOS platform. Am aware of OpenSSL, but I couldn't find a successful method and am still unable to generate this key. Also took a look at SCZ-BasicEncodingRules-iOS but this returns a NSData value and I'm stuck trying to figure out how to try convert it to a NSString.
If you want to create a .PEM format you need to base64 encode the output from the
berData
method. You also need to add the header and footer lines.Test data and code, see the end of the answer for
bytesFromHexString
:Output with test data:
Convert hex-ascii to data: