@@ -0,0 +1,2075 @@
+package com.growthbeat.utils;%0A%0Aimport java.security.InvalidKeyException;%0Aimport java.security.KeyFactory;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.PublicKey;%0Aimport java.security.spec.InvalidKeySpecException;%0Aimport java.security.spec.KeySpec;%0Aimport java.security.spec.X509EncodedKeySpec;%0A%0Aimport javax.crypto.BadPaddingException;%0Aimport javax.crypto.Cipher;%0Aimport javax.crypto.IllegalBlockSizeException;%0Aimport javax.crypto.NoSuchPaddingException;%0A%0Aimport android.util.Base64;%0A%0Apublic class RSAUtils %7B%0A%0A%09private static final String CIPHER_ALGORITHM = %22RSA%22;%0A%09private static final String BLOCK_MODE = %22ECB%22;%0A%09private static final String PADDING_MODE = %22PKCS1Padding%22;%0A%09private static final String TRANSFORMATION = CIPHER_ALGORITHM + %22/%22 + BLOCK_MODE + %22/%22 + PADDING_MODE;%0A%0A%09public static PublicKey getPublicKey(String base64EncodedPublicKey) %7B%0A%0A%09%09try %7B%0A%09%09%09byte%5B%5D keyData = Base64.decode(base64EncodedPublicKey, Base64.DEFAULT);%0A%09%09%09KeySpec keySpec = new X509EncodedKeySpec(keyData);%0A%09%09%09KeyFactory keyFactory = KeyFactory.getInstance(CIPHER_ALGORITHM);%0A%09%09%09return keyFactory.generatePublic(keySpec);%0A%09%09%7D catch (NoSuchAlgorithmException e) %7B%0A%09%09%09return null;%0A%09%09%7D catch (InvalidKeySpecException e) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%7D%0A%0A%09public static String encrypt(String data, String base64EncodedPublicKey) %7B%0A%0A%09%09byte%5B%5D dataBytes = data.getBytes();%0A%09%09PublicKey publicKey = getPublicKey(base64EncodedPublicKey);%0A%09%09byte%5B%5D encryptedDataBytes = encrypt(dataBytes, publicKey);%0A%09%09return Base64.encodeToString(encryptedDataBytes, Base64.DEFAULT);%0A%0A%09%7D%0A%0A%09public static byte%5B%5D encrypt(byte%5B%5D data, PublicKey publicKey) %7B%0A%0A%09%09try %7B%0A%09%09%09Cipher encryptCipher = Cipher.getInstance(TRANSFORMATION);%0A%09%09%09encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);%0A%09%09%09return encryptCipher.doFinal(data);%0A%09%09%7D catch (IllegalBlockSizeException e) %7B%0A%09%09%09return null;%0A%09%09%7D catch (BadPaddingException e) %7B%0A%09%09%09return null;%0A%09%09%7D catch (InvalidKeyException e) %7B%0A%09%09%09return null;%0A%09%09%7D catch (NoSuchAlgorithmException e) %7B%0A%09%09%09return null;%0A%09%09%7D catch (NoSuchPaddingException e) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%7D%0A%0A%7D%0A

Add RSAUtils class