I have a C# Web API service that I need to access with my mobile app. In the header I encrypt the login information using a public private key pairing. I had this working well in the simulator was getting it across very nicely.
try
{
byte[] mod = Base64.decode("Removed");
byte[] exp = Base64.decode("Removed");
BigInteger modulus = new BigInteger(1, mod);
BigInteger pubExp = new BigInteger(1, exp);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(modulus, pubExp);
RSAPublicKey key = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherData = cipher.doFinal(text.getBytes("UTF-8"));
String encrypted = Base64.encode(cipherData);
return encrypted.replace("\n", "");
} catch (Exception ex){
return ex.toString();
}
Once I tried to build the app for Android so I can test it on another platform I got a bunch of errors, many seemed to be pointing to this. I had issues getting this working in the first place so I posted on Stackoverflow and I was pointed towards Bouncy Castle. I am having a difficult time converting this to something that will work with Bouncy Castle, any tips or advise on where to look?