masterbeta
Messages postés4Date d'inscriptionsamedi 5 mars 2011StatutMembreDernière intervention11 mars 2011
-
10 mars 2011 à 17:27
walid50825000 -
27 mars 2013 à 12:55
Bonjour! J'ai le code suivant:(encryption AES 128b)
//Encrypt a plain text from a file using the random 128bits AES key
public static byte[] cryptWithAES(String plainFile, byte[] secretKey, String cipherFile) {
// Write to file
FileOutputStream fOut = null;
fOut = new FileOutputStream(cipherFile);
fOut.write(encrypted_text);
fOut.close();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
throw new RuntimeException();
} catch (InvalidKeyException e) {
e.printStackTrace();
throw new RuntimeException();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
throw new RuntimeException();
} catch (BadPaddingException e) {
e.printStackTrace();
throw new RuntimeException();
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
throw new RuntimeException();
}
catch (IOException e){
e.printStackTrace();
throw new RuntimeException();
}
return encrypted_text;
}
//Decrypt an encrypted text form a file using AES key
public static byte[] decryptInBytesWithAES(String cipherFile, byte[] secretKey, String plainFile) {
// Encrypt a plain text using the public RSA key
public static byte[] cryptWithRSAPublicKey(byte[] plainText,RSAPublicKey publicKey) {
//COMPLETER CECI
}
// Decrypt an encrypted text using RSA key
public static byte[] decryptWithRSAPrivateKey(byte[] cipherText,RSAPrivateKey privateKey) {
//COMPLETER CECI
}
// Alice generates public and private keys and saves them to "private_rsa.key" and "public_rsa.key"
RSAEncryption.setKeyPair("private_rsa.key","public_rsa.key");
// Get RSA public and private keys from files
RSAPublicKey rsaPublicKey=RSAEncryption.getPublicKey("public_rsa.key");
RSAPrivateKey rsaPrivateKey=RSAEncryption.getPrivateKey("private_rsa.key");
// Bob generates a secret AES key
byte[] aesSecretKey=AESEncryption.generateKeyAES128().getEncoded();
//Bob encrypts his file using his secret key
byte[] encrypted_text = AESEncryption.cryptWithAES("texteclair.txt",aesSecretKey,"cipherText_bob.txt");
System.out.println("ENCRYPTED TEXT :"+new String(encrypted_text)+" \n");
// Bob encryptes k_key using Alice RSA public key
byte[] k_encrypted = RSAEncryption.cryptWithRSAPublicKey(aesSecretKey,rsaPublicKey);
System.out.println("ENCRYPTED AES KEY :"+new String(k_encrypted)+" \n");
// Alice decrypts Bob AES symmetric key using her private RSA key
byte[] k_decrypted =RSAEncryption.decryptWithRSAPrivateKey(k_encrypted,rsaPrivateKey);
System.out.println("DECRYPTED AES KEY :"+new String(k_decrypted)+" \n");
// Alice decrypts Bob text using Bob AES symmetric key
byte[] decrypted_text= AESEncryption.decryptInBytesWithAES("cypherText_bob.txt", k_decrypted,"texteclair_alice.txt");
System.out.println("DECRYPTED TEXT :"+new String(decrypted_text)+" \n");
}
}
La probleme est que dans les places ou est ecrit //COMPLETER CECI, je doit completer le code mais pas beaucoup des idees comment je peux faire ca...
la condition est suivante: Il vous est demande d'ecrire un programme pour :
{ Generer une cle privee et une cle publique RSA de 2048 bits.
{ Generer de maniere (pseudo) aleatoire des cles symetriques de 128 bits.
{ Chirer avec RSA en utilisant la cle publique.
{ Dechirer avec RSA en utilisant la cle privee.
Partie 2 : Chirement AES (4 pts)
Il vous est demande d'ecrire un programme pour :
{ Chirer avec AES en utilisant une cle symetrique de 128 bits.
{ Dechirer avec AES en utilisant une cle symetrique de 128 bits
Je veux votre aide s'il vous plaît
Au bord d'une image (converti en une tab octets puis crypt) image cryptée est obtenue. Processus normale
Le déchiffrement inverse ((converti en un tableau d'octets, puis décrypté) me montre une erreur. Outre le bloc inappropriée
J'espère que votre aide s'il vous plaît.