I'm coding a RSA algorithm to encrypt a string to send to a VisualBasic webservice. Unfortunatelly the VB RSAcryptoserviceprovider always gives me an exception "Bad data" and i this the problem is the encoding. The VisualBasic code receives the string and converts it to a byte array using windows-1252 encoding and them decrypts it.
In my Java code i'm encrypting using this:
private static String encryptBlock(Cipher cipher, String textToEncrypt) {
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
String encrypted = new String(cipher.doFinal(textToEncrypt.getBytes(Charset.defaultCharset())), "windows-1252");
return encrypted;
}
When i 'system.out.print' the encrypted string it gives me strange chars like �. Does it means that me windows-1252 encoding is wrong right? What am i doing wrong here? Note that i can only make changes to the Java code and not the VB.
Thank you!