RSA Encryption & Decryption in Java
<p>I have written a program to encrypt a string with RSA private key then add encrypted text to another string and encrypt it with AES when i decrypt the cipher text with AES once its working but while decrypting with RSA public key it gives Data Must start with zero er</p>

<pre><code>public static void main(String args[]) throws NoSuchAlgorithmException,InvalidKeyException,NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, FileNotFoundException, IOException, ClassNotFoundException, InvalidAlgorithmParameterException
{


        String message = "Hii mesg from client";

        String md5 =genMD5(message);

        System.out.println("MD5:::::" +md5);

        String cipherstr=encryptmd5(md5);

        System.out.println("encrypted md5:::::"+cipherstr);

        String clientmesg = message+"@@@"+cipherstr;
        System.out.println("res::"+clientmesg); 
        KeyGenerator keyGen = KeyGenerator.getInstance("AES");
        keyGen.init(128);
        SecretKey secretKey = keyGen.generateKey();
        Cipher aesCipher = Cipher.getInstance("AES");
        aesCipher.init(Cipher.ENCRYPT_MODE,secretKey);

        byte[] byteDataToEncrypt = clientmesg.getBytes();
        byte[] byteCipherText = aesCipher.doFinal(byteDataToEncrypt); 
        String strCipherText = new BASE64Encoder().encode(byteCipherText);
        System.out.println("Cipher Text generated using AES is " +strCipherText);


        aesCipher.init(Cipher.DECRYPT_MODE,secretKey);
        byte[] byteDecryptedText = aesCipher.doFinal(byteCipherText);
        String n = new String(byteDecryptedText);
        System.out.println(" Decrypted Text message is " +n);



        int count =0;
        String decmd5="";
        for(int i=0;i&lt;n.length();i++)
        {
            if(n.charAt(i)=='@')
            {
                count++;
            }

            if(count&gt;=3 &amp;&amp; n.charAt(i)!='@')
            {
                decmd5+=n.charAt(i);
            }
        }


        byte[] dect = decmd5.getBytes();
        byte[] md =decrypt(decmd5);
        String emd=new String(md);
        System.out.println("MD5:::2323344:"+decmd5);

}

public static byte[] decrypt(String dect) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, FileNotFoundException, IOException, ClassNotFoundException 
{
    // TODO Auto-generated method stub
    ObjectInputStream in3 = new ObjectInputStream(new FileInputStream("Publickeys.srt"));
    cert  c3=(cert)in3.readObject();

    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.DECRYPT_MODE,c3.apub);
    byte[] c= dect.getBytes();

    byte[] decMd= cipher.doFinal(c, 0, 256);
    String tty = new String(decMd);
    byte[] r = new BASE64Decoder().decodeBuffer(tty);
    //System.out.println("Message decrypted: "+new String(decMd));
    return r;
}
public static String encryptmd5(String md5) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, FileNotFoundException, IOException, ClassNotFoundException 
{
    // TODO Auto-generated method stub
    ObjectInputStream in = new ObjectInputStream(new FileInputStream("SenderCertificate.srt"));
    SenderCert  c1=(SenderCert)in.readObject();
    Cipher cipher = Cipher.getInstance("RSA");

    cipher.init(Cipher.ENCRYPT_MODE,c1.pr);

    byte[] ciphertext = cipher.doFinal(md5.getBytes());
    String strCipherText = new BASE64Encoder().encode(ciphertext);
    in.close();
    return strCipherText;
   }
</code></pre>
