Quoi changer pour travailler avec AES 256 bits

ImFaith Messages postés 57 Date d'inscription dimanche 6 décembre 2009 Statut Membre Dernière intervention 17 mars 2015 - 28 avril 2011 à 23:13
ImFaith Messages postés 57 Date d'inscription dimanche 6 décembre 2009 Statut Membre Dernière intervention 17 mars 2015 - 29 avril 2011 à 16:40
Bonjour ;
j'ai trouvé un code de AES dans ce site :Tapez le texte de l'url ici.
voici le code :


import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;

/**
* This program generates a AES key, retrieves its raw bytes, and
* then reinstantiates a AES key from the key bytes.
* The reinstantiated key is used to initialize a AES cipher for
* encryption and decryption.
*/

public class AES {

/**
* Turns array of bytes into string
*
* @param buf Array of bytes to convert to hex string
* @return Generated hex string
*/
public static String asHex (byte buf[]) {
StringBuffer strbuf = new StringBuffer(buf.length * 2);
int i;

for (i = 0; i < buf.length; i++) {
if (((int) buf[i] & 0xff) < 0x10)
strbuf.append("0");

strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
}

return strbuf.toString();
}

public static void main(String[] args) throws Exception {

String message="This is just an example";

// Get the KeyGenerator

KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128); // 192 and 256 bits may not be available


// Generate the secret key specs.
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();

SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");


// Instantiate the cipher

Cipher cipher = Cipher.getInstance("AES");

cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

byte[] encrypted =
cipher.doFinal((args.length == 0 ?
"This is just an example" : args[0]).getBytes());
System.out.println("encrypted string: " + asHex(encrypted));

cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] original =
cipher.doFinal(encrypted);
String originalString = new String(original);
System.out.println("Original string: " +
originalString + " " + asHex(original));
}
}


il marche pour 128 bits ,je veux travailler avec 256 bits mais il ne marche pas ,il cité dans le site qu'on doit télécharger :unlimited strength version ;mais j'ai pas le trouver,comment faire ?

1 réponse

ImFaith Messages postés 57 Date d'inscription dimanche 6 décembre 2009 Statut Membre Dernière intervention 17 mars 2015
29 avril 2011 à 16:40
Salut ;
c'est bon ,j'ai résolu le probléme pour le nbre de bit mais le probléme qui se pose :
est ce que je peux modifier la clé utilisée pour le chiffrement qui est :AES ?
je veux utiliser la mienne ?
0
Rejoignez-nous