Decryption using private key issue in Android
<p>I am getting an encrypted string from the backend server, which I need to decrypt using private key in Android.The decryption works, but it appends a special character at the end of the decrypted string.
Here is the code I am using:</p>

<pre><code>public static String decryptString(String value, Context context){

    value = "Ss7LVqgWeamgPGkt62qSNydTJnwiUet8UemYWR0jzCLOvtW+RazpJmGG657/nWhu5UQGXzEMwIK1jcBXIXkw3EAX6WdocYBKpVJPWpmlEbf4IzPcev67wgx4vd3ylK8KrpPDj92EKE6ElDi/U91e+VS3bhURHye0w9ncaITTm+szGFiDL/fcy+0hnrYJdA3IrElZntYk14SCccb2M0LJ+nTFdfzEgsUH8vW5ei986d4HTKUqBvkoU+JAtHXTYq1sKNSd4L3Xm5fZ0OPpdIKEWqHDntjsMRsX62eTON+iC1OVsKK2vRqvSbVLvE45ww3N6iZNBG1gewcC8v5wJwonmA==";
    byte[] decodedBytes = null;
    try {
        //Cipher c = Cipher.getInstance("AES/ECB/PKCS7Padding", "AndroidOpenSSL");
        //Cipher c = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", "AndroidOpenSSL");
        Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
        c.init(Cipher.DECRYPT_MODE,  getPrivateKey(context) );

        decodedBytes = c.doFinal(Base64.decode(value, Base64.DEFAULT));


        //decodedBytes = c.doFinal(value.getBytes("ISO-8859-1"));

    } catch (Exception e) {
        e.printStackTrace();
    }

    return new String(decodedBytes);
}  

public static PrivateKey getPrivateKey(Context context){

    // reads the key_public key stored in a file
    InputStream is = context.getResources().openRawResource(R.raw.key_private);

    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
    String line = null;

    try {


        while ((line = br.readLine()) != null)
            lines.add(line);


        // removes the first and last lines of the file (comments)
        if (lines.size() &gt; 1 &amp;&amp; lines.get(0).startsWith("-----") &amp;&amp; lines.get(lines.size()-1).startsWith("-----")) {
           lines.remove(0);
         lines.remove(lines.size()-1);
        }

        // concats the remaining lines to a single String
        StringBuilder sb = new StringBuilder();
        for (String aLine: lines)
            sb.append(aLine);
        String keyString = sb.toString();
        byte [] encoded = Base64.decode(keyString, Base64.DEFAULT);



    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");

        PrivateKey myPrivKey = keyFactory.generatePrivate(keySpec);

        return myPrivKey;

    }catch (Exception e){

        e.printStackTrace();
    }
    return null;

}
</code></pre>

<p>Finally, I call the first function from the main activity:</p>

<pre><code>String decryptedString =  AppUtils.decryptString(encryptedString, MainActivity.this);
</code></pre>

<p>I am attaching my private key for reference:</p>

<pre><code>-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDuDOP1sBXEKUwR
WQcH459iGj74fGPqnIFJ+cOxNFFeymXs0L0u4n7v6NCAGvZJ5HtdWeUbT+xMMNMW
k8swrQs/qZ36KXzxhL6hy0gj4i86G5L73vQ39g/qlnxhfR+OxhVnDUE4TOt9xhN9
20Mf6xVhVOVmUQwhny6sQqvkhaebzJ32QuTlHFVT8mMGSTwXcHUqRi2ApeyRW9ln
BCLf/P5k+/O5W4lRmyfvumZoipegf0e75hGmgJYxXETomU50DmLMNdQ05/rlpcW5
FEm3Gf60pd+/mqkB+3LlyTPAM7sEfwKgL+CZSqYtz3O/m7tYSK7BtCIbE1bvksjj
bPQA1DYXAgMBAAECggEAZDvDRLEnCRjGccuFvVmnw7v/ZcuimqfZfJeRQa0g0gPx
FNzzu6kc/9GM8VPo/kYZd74hTPXDLnWkfC4w8Ub7pIu7/Bi6Bkv5pNCeiJV1g0cX
BbzkIigWnZVNvBLeVdSsMF8RZi5lPelITcckJW1r7Da9/O4FaKbJFTlhfXCVmXCn
74Bs0q8QZHA/WLwcy5DP+uqdko8T3vtBSPx7HEBbEhy94SEAsQfkdLTa0KQ2WlLI
ythR5DH0GUIoTIBeFsM7w2Ldj7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XIYqUVlvX7rmgg==��
</code></pre>

<p>The decrypted string should end with "==".Can someone kindly help me to figure out, how to remove the special characters at the end of the decrypted string.</p>

<p>Thanks</p>