Exception iArrayIndexOutOfBounds Exception
ceci est une class simple qui permet de crypeter des données saisies pas l'utilisateur !!! le problème c'est que j'ai une exception que j'ai pas pu résoudre :? si vous pouvez m'aidez !!
merci
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| public static void main(String[] args) {
String plaintext = args[0];
System.out.println("plaintext = " + plaintext);
MyRSA rsa = new MyRSA();
rsa.generateKeyPair();
byte[] publicKey = rsa.getPublicKeyInBytes();
byte[] privateKey = rsa.getPrivateKeyInBytes();
byte[] ciphertext = rsa.crypt(plaintext);
System.out.println("ciphertext = " + new BigInteger(ciphertext));
rsa.setPublicKey(publicKey);
rsa.setPrivateKey(privateKey);
String plaintext2 = rsa.decryptInString(ciphertext);
System.out.println("plaintext2 = " + plaintext2);
if (!plaintext2.equals(plaintext)) System.out.println("Error: plaintext2 != plaintext");
}
private BigInteger crypt(BigInteger plaintext) {
return plaintext.modPow(publicKey.getPublicExponent(), publicKey.getModulus());
}
private BigInteger decrypt(BigInteger ciphertext) {
return ciphertext.modPow(privateKey.getPrivateExponent(), privateKey.getModulus());
}
/**
* Ajoute un byte de valeur 1 au début du message afin d'éviter que ce dernier
* ne corresponde pas à un nombre négatif lorsqu'il sera transformé en
* BigInteger.
*/
private static byte[] addOneByte(byte[] input) {
byte[] result = new byte[input.length+1];
result[0] = 1;
for (int i = 0; i < input.length; i++) {
result[i+1] = input[i];
}
return result;
}
/**
* Retire le byte ajouté par la méthode addOneByte.
*/
private static byte[] removeOneByte(byte[] input) {
byte[] result = new byte[input.length-1];
for (int i = 0; i < result.length; i++) {
result[i] = input[i+1];
}
return result;
}
} |