question

Rohit Bhardwaj avatar image
Rohit Bhardwaj asked ·

How to generate RSA Public Key using modulus and exponent in swift 4?

Hi,

I want to get RSA Public Key which is used before making payments. I have a JAVA Code but unable to find similar code in swift 4. Can you please help me out, I'm really stuck at this point. Here is the code for JAVA.

public static PublicKey getPublicKey(final BigInteger modulus, final BigInteger exponent) throws Exception {
                
final KeyFactory factory = KeyFactory.getInstance("RSA");
final PublicKey publicKey = factory.generatePublic(new RSAPublicKeySpec(modulus, exponent));
return publicKey; }

Thanks in advance.
Payments
1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rohit,


This is a developer question outside the Scope of Clover API/SDK/Services, I recommend using another forum (stackoverflow?) to get a response.

Good day!
1 Like 1 · ·

1 Answer

Frank Faustino avatar image
Frank Faustino answered ·
Hi, @Rohit Bhardwaj.

Apple has SecKey API that allows you to create asymmetric RSA key pairs. In particular, the SecKeyCreateWithData function allows you to create the RSA public key with the modulus and exponent from Clover's Developer Pay API. You'll have to convert the modulus and exponent from base 10 to DER integers, then encode them in PKCS1 format.

I've created an example implementation here: https://github.com/frankfaustino/clover-developer-pay-api-swift
Share
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community