- Home /

This question was **closed** Apr 02 at 09:46 PM by Clover_Community_Bot for the following reason: automated

I am working with the payment API. I am trying to create the RSA Public Key. I have retrieved the modulus and exponent from the call to /v2/merchant/{mId}/pay/key.

According to the documentation, the modulus and exponent are base10 strings. So I need to convert that to a byte array. I am having trouble figuring out how to do this. Is there a code example anywhere that reflects this?

I tried converting the string to a biginteger and then retrieving bytes, but that does not seem to work. Any ideas on this?

Comment

**Answer** by Jacob Abrams
·
Nov 19, 2015 at 04:32 PM

The example code in this FAQ should help: https://docs.clover.com/faq#how-do-i-... You can simply pass the string to a new BigInteger like so: `new BigInteger(modulus)`

I am using C#. These two generate different values. I am not sure why, but the bouncy castle version allowed me to generate the public key. My guess is C# BigInteger.Parse is expecting a base64 string

```
public byte[] GetBytesFromBase10String(string base10)
{
var b = BigInteger.Parse(base10);
return b.ToByteArray();
}
public byte[] GetBytesFromBase10StringWithBouncyCastle(string base10)
{
var bigInt = new Org.BouncyCastle.Math.BigInteger(base10, 10);
return bigInt.ToByteArray
```

Verified it worked. I was able to submit a payment using the Bouncy Castle method.

**Answer** by Jonathan
·
Nov 19, 2015 at 04:36 PM

I think I have it, but I am not sure. I was able to use BouncyCastle to convert the string to big integer. Now, just need to see if this works:

```
var modulus = new Org.BouncyCastle.Math.BigInteger(modulusBase10, 10);
var exponent = new Org.BouncyCastle.Math.BigInteger(exponentBase10, 10);
RSACryptoServiceProvider rsaObj = new RSACryptoServiceProvider();
//Create a new instance of the RSAParameters structure.
RSAParameters rsaPars = new RSAParameters();
rsaPars.Modulus = modulus.ToByteArray();
rsaPars.Exponent = exponent.ToByteArray();
Console.WriteLine("MODULUS in STRING FORM:>" + Convert.ToBase64String(rsaPars.Modulus));
//Import key parameters into RSA.
rsaObj.ImportParameters(rsaPars);
return rsaObj.ExportCspBlob(false);
```

Clover Developer Community

Follow
### Follow this Question

Copyright © 2010-16 DZone, Inc. - All rights reserved.

- Anonymous
- Sign in
- Create
- Ask a question
- Post an idea
- Create an article
- Spaces
- App Market Developer Platform
- Clover GO
- Semi-Integration
- Explore
- Topics
- Questions
- Articles
- Users
- Badges