Basit bir "String" testini ileri geri kodlamaya çalışıyorum.Java RSA Şifreleme
: şifreleme gayet güzel çalışıyor olsa
public static String encode(Key publicKey, String data) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { byte[] byteData = data.getBytes(); // convert string to byte array Cipher cipher = Cipher.getInstance(ALGORITHM); // create conversion processing object cipher.init(Cipher.ENCRYPT_MODE, publicKey); // initialize object's mode and key byte[] encryptedByteData = cipher.doFinal(byteData); // use object for encryption return new String(encryptedByteData); // convert encrypted byte array to string and return it } public static String decode(Key privateKey, String data) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { byte[] byteData = data.getBytes(); // convert string to byte array Cipher cipher = Cipher.getInstance(ALGORITHM); // create conversion processing object cipher.init(Cipher.DECRYPT_MODE, privateKey); // initialize object's mode and key System.out.println(byteData.length); byte[] decryptedByteData = cipher.doFinal(byteData); // use object for decryption return new String(decryptedByteData); // convert decrypted byte array to string and return it }
Ancak, ben sadece "test" şifreleyerek dan aldık dize şifresini çözmek için çalışırken, ben hariç şu olsun (ALGORITMASı "RSA" dır) javax.crypto.IllegalBlockSizeException: Veriler 256 byte
bunu deşifre edebilmek amacıyla 256 parçaları içinde şifrelenmiş bayt bölünmüş Should daha uzun olmamalıdır? here kaynaktan
Ah, mükemmel, teşekkürler, mükemmel çalışıyor! Evet, sanırım şifreli bayt dizisini bir String'e dönüştürdüğümde bozulma. – arik