import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;

// --------------------------------------------------
// Exemple d'utilisation du JCE
// Generation d'une cle a partir d'un mot de passe (String)
// --------------------------------------------------

class TestJCE02 {
    private static byte[] crypter(String password, String msg)	{
	// Indications:
	//    - utiliser "PBEWithMD5AndDES" pour le KeyFactory
	//    - utiliser "PBEWithMD5AndDES" pour le Cipher
	//    - penser a convertir la String en byte[] via la methode getBytes() avant de chiffrer
    }
	
    private static String decrypter(String password, byte[] buffer) {
	// Idem ci-dessus...
    }
	
    public static void main(String[] args) {
	if (args.length<2)
	    {
		System.out.println("Usage: java TestJCE02 <password> <message>");
		System.exit(0);
	    }
	
	String thePassword = args[0];
	String theMessage = args[1];
	
	System.out.println("message initial = \""+theMessage+"\"");
	byte[] buf = crypter(thePassword, theMessage);
	System.out.println("message crypte  = \""+(new String(buf))+"\"");
	String msg = decrypter(thePassword, buf);
	System.out.println("message final   = \""+msg+"\"");
    }
}
