Rechercher : dans
Par :

Cryptage avec RSA

Surye68, le 3 fév 2009 à 12:55:40 
 Signaler ce message aux modérateurs

Bonjour,

Avec le code ci dessous j'arrive à crypter et à décrypter un message mais j'ai pas d'idée pour crypter et décrypter un fichier avec l'algorithme RSA.
Faites moi part de vos idées SVP.
Merci


import java.math.BigInteger;
import java.security.InvalidParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;



/**
* @author Simo
*
*/
public class CryptageDecryotage {



public static KeyPair generateKeyPair() throws Exception
{
try {
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
keyPairGen.initialize(2048, rand);
KeyPair keyPair = keyPairGen.generateKeyPair();

return keyPair;
}
catch (NoSuchAlgorithmException ex) {
throw new Exception("Probleme lors de la création de la pair de clef : "+ex.getMessage());
}
catch (InvalidParameterException ex) {
throw new Exception("Probleme lors de la création de la pair de clef : "+ex.getMessage());
}
}

//Crypter avec la clef publique

public static byte[] cryptWithRSAPublicKey(byte[] plainText,RSAPublicKey clefPublique) {
BigInteger msgEnBigInteger = new BigInteger(plainText);
BigInteger msgCrypte = msgEnBigInteger.modPow(clefPublique.getPublicExponent(), clefPublique.getModulus());
return msgCrypte.toByteArray();
}

//Décrypter avec la clef privé

public static byte[] decryptWithRSAPrivateKey(byte[] cipherText,RSAPrivateKey clefPrivee) {
BigInteger msgADecrypteEnBigInt = new BigInteger(cipherText);
BigInteger msgDecrypteEnBigInt = msgADecrypteEnBigInt.modPow(clefPrivee.getPrivateExponent(), clefPrivee.getModulus());
return msgDecrypteEnBigInt.toByteArray();
}

// le test

public static void main(String[] args) throws Exception
{
KeyPair myKeyPair = generateKeyPair();

byte[] encrypted = CryptageDecryotage.cryptWithRSAPublicKey("projet cryptage test salut".getBytes(), (RSAPublicKey)myKeyPair.getPublic());
byte[] decrypted = CryptageDecryotage.decryptWithRSAPrivateKey(encrypted, (RSAPrivateKey)myKeyPair.getPrivate());
System.err.println(new String(encrypted));
System.err.println(new String(decrypted));


}

}

Configuration: Windows Vista
Firefox 3.0.5

Meilleures réponses pour « Cryptage avec RSA » dans :
Le chiffrement avec RSA Voir le système RSA Le premier algorithme de chiffrement à clé publique (chiffrement asymétrique) a été développé par R.Merckle et M.Hellman en 1977. Il fut vite rendu obsolète grâce aux travaux de Shamir, Zippel et Herlestman, de célèbres...
Logiciels de Cryptographie et Stéganographie Voir1. Cryptographie 1.1 Cryptozor 1.2 Krypto Zone 1.3 TrueCrypt 1.4 FlashCrypt 1.5 Autres logiciels 2. Stéganographie 2.1 JPEGX 2.2 Autres logiciels 1. Cryptographie Pour bien comprendre le principe de la cryptographie, je vous...
Télécharger Crypt For Free Voirc'est un utilitaire gratuit de cryptage de données.Vous pourrez crypter vos fichier en utilisant trois algorithmes de chiffrages, le Blowfish (448 bits), AES (256 bits) et DESX (128 bits). Vous pourrez envoyer des courriels chiffrés via le module...
Télécharger Crypt Edit VoirCrypt Edit est un puissant éditeur de texte en remplacement à Windows NotePad et WordPad. Il comprend des fonctions intéressantes telles que la cryptographie (algorithmes RC4, MD5). Il peut également exporter facilement les documents au format...
Cryptographie VoirPourquoi la cryptographie? L'homme a toujours ressenti le besoin de dissimuler des informations, bien avant même l'apparition des premiers ordinateurs et de machines à calculer. Depuis sa création, le réseau Internet a tellement évolué qu'il est...
Collection CommentÇaMarche.net