IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Cryptage et Décryptage RSA


Sujet :

avec Java

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Points : 5
    Points
    5
    Par défaut Cryptage et Décryptage RSA
    Bonsoir à tous.

    Tout d'abord, toutes mes excuses si le sujet est mal placé, il me semblait que cette section était la plus appropriée, étant donné que je suis un débutant en Java.

    Mon problème concerne le cryptage et le décryptage avec une paire de clés RSA.
    J'ai tout d'abord crypté et décrypté un fichier, puis affiché le contenu de ce décryptage dans le terminal (ce qui s'est très bien déroulé).

    En ce qui concerne la gestion de clés, je génère des clés de taille 2048, que je vais stocker dans un fichier public.key et .private.key
    Puis, je récupère ces clés dans une nouvelle KeyPair afin de tester cette fonctionnalité, qui m'est demandée.

    Dans un dernier temps, mon but est de récupérer le contenu d'un fichier d'entrée, le crypter et envoyer ce contenu crypté dans un nouveau fichier (ce qui est fait).
    Mon problème vient alors lors de la décryption, quand j'essaye de reprendre les données binaires de ce fichier ainsi crypté, je n'arrive pas à les décrypter.

    J'aimerais avoir votre avis sur le problème si possible.

    Voila mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    package com.bodom.ghosty;
     
    import javax.crypto.BadPaddingException;
    import javax.crypto.Cipher;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.NoSuchPaddingException;
    import java.io.*;
    import java.math.BigInteger;
    import java.nio.charset.Charset;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.nio.file.StandardOpenOption;
    import java.security.*;
    import java.security.spec.InvalidKeySpecException;
    import java.security.spec.RSAPrivateKeySpec;
    import java.security.spec.RSAPublicKeySpec;
    import java.util.List;
     
    public class EncryptionUtil {
     
        /**
         * Generate a pair of RSA keys
         *
         * @return A keypair of RSA keys
         * @throws NoSuchAlgorithmException
         */
        public static KeyPair keyGenerate() throws NoSuchAlgorithmException {
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(2048);
            return keyGen.genKeyPair();
        }
     
     
        /**
         * Crypt data
         *
         * @param data      Data to encrypt
         * @param publicKey PublicKey used to crypt
         * @return          The crypted data
         * @throws NoSuchAlgorithmException
         * @throws NoSuchPaddingException
         * @throws InvalidKeyException
         * @throws IllegalBlockSizeException
         * @throws BadPaddingException
         */
        private static byte[] rsaEncryption(byte[] data, PublicKey publicKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
            Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            return cipher.doFinal(data); //Encrypte data avec le cipher, tel qu'il a été paramétré, ici en mode RSA, en encryption, encryption qui va utiliser la clé publique.
        }
     
     
        /**
         * Encrypt a file
         *
         * @param file      Path of the file to crypt
         * @param charset   Charset used to read the file
         * @param publicKey PublicKey used to crypt the file
         * @return          A byte array which contains the crypted lines of the file
         * @throws IOException
         * @throws IllegalBlockSizeException
         * @throws InvalidKeyException
         * @throws BadPaddingException
         * @throws NoSuchAlgorithmException
         * @throws NoSuchPaddingException
         */
        public static byte[] encryption (Path file, Charset charset, PublicKey publicKey) throws IOException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
            List<String> lines = Files.readAllLines(file, charset); //Récupère toutes les lignes du fichier
            byte[] cryptedfile = null; //contiendra les bytes cryptés du fichier
            for(String line : lines) { //on parcourt toutes les lignes
                byte[] crypt = rsaEncryption(line.getBytes(), publicKey); //On crypte la ligne du fichier
                byte[] tmp;
                tmp = cryptedfile; //variable temporaire qui contiendra les bytes cryptés précédemment
     
                if (tmp != null) { //on initialise cryptedfile pour qu'il accueille les bytes cryptées précédemment + les courants
                    cryptedfile = new byte[crypt.length + tmp.length];
                }
                else cryptedfile = new byte[crypt.length];
     
                System.arraycopy(crypt, 0, cryptedfile, 0, crypt.length); //Concaténation des tableaux de bytes
                if (tmp != null) {
                    System.arraycopy(tmp, 0, cryptedfile, crypt.length, tmp.length);
                }
            }
            return cryptedfile;
        }
     
     
        /**
         * Decrypt data
         *
         * @param crypteddata Crypted data to decrypt
         * @param privateKey  PrivateKey used to decrypt
         * @return            The decrypted data
         * @throws NoSuchAlgorithmException
         * @throws NoSuchPaddingException
         * @throws InvalidKeyException
         * @throws IllegalBlockSizeException
         * @throws BadPaddingException
         */
        private static byte[] rsaDecryption(byte[] crypteddata, PrivateKey privateKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
            Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding"); //cipher en mode RSA
            cipher.init(Cipher.DECRYPT_MODE, privateKey); //cipher en mode Decryptage, avec la clé privée en param
            return cipher.doFinal(crypteddata); //décryptage du tableau de bytes et on renvoie un tableau de bytes décryptées
        }
     
     
        /**
         * Read the bytes of a file
         *
         * @param file is the file to read
         * @return     the bytes of the file
         * @throws IOException
         */
        private static byte[] readBytesInFile (Path file) throws IOException {
            byte[] result = new byte[(int)Files.size(file)];
            try {
                try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file.getFileName().toString()))) {
                    int bytesRead = 0;
                    while (bytesRead < result.length) {
                        int bytesLeft = result.length - bytesRead;
                        int bytesGet = inputStream.read(result, bytesRead, bytesLeft);
                        if (bytesGet > 0) {
                            bytesRead += bytesGet;
                        }
                    }
                }
            } catch (IOException e) {
                System.out.println(e);
            }
            return result;
        }
     
        /**
         * Decrypt a file
         *
         * @param file       Path of the file to decrypt
         * @param privateKey PrivateKey used to decrypt the file
         * @return           A byte array which contains the decrypted lines of the file
         * @throws IOException
         * @throws IllegalBlockSizeException
         * @throws InvalidKeyException
         * @throws BadPaddingException
         * @throws NoSuchAlgorithmException
         * @throws NoSuchPaddingException
         */
        public static byte[] decryption(Path file, PrivateKey privateKey) throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, IOException {
            byte[] crypteddata = readBytesInFile(file); //lecture des bytes du fichier spécifié
            int offset = 0;
            byte[] decryptedfile = null;
     
            //Parcours de tous les bytes du fichier
            while (offset < crypteddata.length) {
                byte[] outputBytes;
                byte[] tmp;
     
                //Si il reste moins de 200 bytes
                if(crypteddata.length - offset < 200 ) {
                    //Copie du contenu restant de crypteddata dans outputBytes
                    outputBytes = new byte[crypteddata.length - offset];
                    System.arraycopy(crypteddata, offset, outputBytes, 0, crypteddata.length - offset);
     
                    //Decryptage de la partie de bytes
                    byte[] decrypt = rsaDecryption(outputBytes, privateKey);
     
                    //Update de la taille pour recevoir la concaténation
                    tmp = decryptedfile;
                    if (tmp != null) {
                        decryptedfile = new byte[decrypt.length + tmp.length];
                    }
                    else decryptedfile = new byte[decrypt.length];
     
                    //Concaténation des bytes décryptés
                    System.arraycopy(decrypt, 0, decryptedfile, 0, decrypt.length);
                    if (tmp != null) {
                        System.arraycopy(tmp, 0, decryptedfile, decrypt.length, tmp.length);
                    }
                    break;
                }
     
                //Création de la partie de bytes, et copie du contenu de crypteddata de offset à offset+200 et mise dans outputBytes de 0 à 200
                outputBytes = new byte[200];
                System.arraycopy(crypteddata, offset, outputBytes, 0, 200);
     
                //Decryptage de la partie de bytes
                byte[] decrypt = rsaDecryption(outputBytes, privateKey);
     
                //Update de la taille pour recevoir la concaténation
                tmp = decryptedfile;
                if (tmp != null) {
                    decryptedfile = new byte[decrypt.length + tmp.length];
                }
                else decryptedfile = new byte[decrypt.length];
     
                //Concaténation dans decryptedfile de la partie de bytes
                System.arraycopy(decrypt, 0, decryptedfile, 0, decrypt.length);
                if (tmp != null) {
                    System.arraycopy(tmp, 0, decryptedfile, decrypt.length, tmp.length);
                }
                offset +=200 ;
            }
            return decryptedfile;
        }
     
        /**
         * Save a key in a file
         *
         * @param modulus  Modulus of the key to save
         * @param exponent Exponent of the key to save
         * @param filename File used to save the keys
         * @throws IOException
         * @throws NoSuchAlgorithmException
         */
        private static void saveKeyToFile (BigInteger modulus, BigInteger exponent, String filename) throws IOException, NoSuchAlgorithmException {
            try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename)))) {
                objectOutputStream.writeObject(modulus);
                objectOutputStream.writeObject(exponent);
            }
        }
     
        /**
         * Save a KeyPair in two files
         *
         * @param keyPair KeyPair to save
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         * @throws FileNotFoundException
         * @throws IOException
         */
        public static void saveKeyPair(KeyPair keyPair) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
     
            RSAPublicKeySpec rsaPublicKeySpec = keyFactory.getKeySpec(keyPair.getPublic(), RSAPublicKeySpec.class);
            saveKeyToFile(rsaPublicKeySpec.getModulus(), rsaPublicKeySpec.getPublicExponent(), "keys/public.key");
     
            RSAPrivateKeySpec rsaPrivateKeySpec = keyFactory.getKeySpec(keyPair.getPrivate(), RSAPrivateKeySpec.class);
            saveKeyToFile(rsaPrivateKeySpec.getModulus(), rsaPrivateKeySpec.getPrivateExponent(), "keys/.private.key");
        }
     
        /**
         * Get a PublicKey from a file
         *
         * @param filename File where the PublicKey is saved
         * @return         The PublicKey get in the file
         * @throws IOException
         * @throws ClassNotFoundException
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         */
        private static PublicKey getPublicKeyFromFile (String filename) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
            try (ObjectInputStream objectInputStream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
                BigInteger modulus = (BigInteger) objectInputStream.readObject();
                BigInteger exponent = (BigInteger) objectInputStream.readObject();
     
                RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(modulus, exponent);
                KeyFactory keyFactory = KeyFactory.getInstance("RSA");
                return keyFactory.generatePublic(rsaPublicKeySpec);
            }
        }
     
        /**
         * Get a PrivateKey from a file
         *
         * @param filename File where the PrivateKey is saved
         * @return         The PrivateKey get in the file
         * @throws IOException
         * @throws ClassNotFoundException
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         */
        private static PrivateKey getPrivateKeyFromFile (String filename) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
            try (ObjectInputStream objectInputStream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
                BigInteger modulus = (BigInteger) objectInputStream.readObject();
                BigInteger exponent = (BigInteger) objectInputStream.readObject();
     
                RSAPrivateKeySpec rsaPrivateKeySpec = new RSAPrivateKeySpec(modulus, exponent);
                KeyFactory keyFactory = KeyFactory.getInstance("RSA");
                return keyFactory.generatePrivate(rsaPrivateKeySpec);
            }
        }
     
        /**
         * Get the RSA keypair from the files
         *
         * @return The Keypair which contains the public and the private key
         * @throws IOException
         * @throws ClassNotFoundException
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         */
        public static KeyPair getKeysFromFiles () throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException{
            PublicKey publicKey = getPublicKeyFromFile("keys/public.key");
            PrivateKey privateKey = getPrivateKeyFromFile("keys/.private.key");
            return new KeyPair(publicKey, privateKey);
        }
     
        public static void main(String[] args) throws InvalidKeySpecException, NoSuchAlgorithmException {
            // Initialization MARCHE
            KeyPair kp = null;
            try {
                kp = EncryptionUtil.keyGenerate();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
     
            //Saving keys part MARCHE
            try {
                saveKeyPair(kp);
            } catch (NoSuchAlgorithmException | InvalidKeySpecException| IOException e) {
                System.out.println("Error during the storage of the keys : " + e);
            }
     
            //Getting keys part MARCHE
            KeyPair keyPair = null;
     
            try {
                keyPair = getKeysFromFiles();
            } catch (ClassNotFoundException | NoSuchAlgorithmException | InvalidKeySpecException | IOException e) {
                System.out.println("Error during the loading of the keys : " + e);
            }
     
            // Crypt part
            byte[] uncrypt = null;
            try {
                if (keyPair != null) {
                    //Cryptage
                    byte[] crypt = encryption(Paths.get("file"), Charset.forName("UTF-8"), keyPair.getPublic());
     
                    //Inscription dans le fichier (même systeme pour DriveUtil)
                    Files.write(Paths.get("cryptedfile"), crypt, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
     
                    //Decryptage
                    uncrypt = decryption(Paths.get("cryptedfile"), keyPair.getPrivate());
                }
            } catch (InvalidKeyException | NoSuchAlgorithmException
                    | NoSuchPaddingException | IllegalBlockSizeException
                    | BadPaddingException | IOException e) {
                System.out.println(e);
            }
     
            String s = new String(uncrypt);
            System.out.println(s);
        }
    }
    Le problème de décryptage est donc surement dans la méthode decryption(), qui s'effectue bien mais ne décrypte pas ; lorsque j'affiche ce qu'elle doit renvoyer, j'obtiens des bytes.
    En même temps que ce problème de décryptage, je rappelle que je suis un débutant en Java.
    Tous conseils en ce qui concerne ma manière de coder ainsi que les conventions de Java sont les bienvenus!

    Merci d'avance pour votre aide.

  2. #2
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 211
    Points : 8 316
    Points
    8 316
    Billets dans le blog
    52
    Par défaut
    De mémoire, sans lire le code, le cryptage se fait à partir d'un byte[] et donne et donne byte[]. Le décryptage fait la même chose.
    Donc tu dois convertir ton byte[] en String.
    Genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String myDecryptedText = new String(decryptedContent);
    Cordialement,
    Patrick Kolodziejczyk.
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Points : 5
    Points
    5
    Par défaut
    Bonjour!

    Merci pour votre réponse.
    En effet, j'ai lu qu'il fallait faire ça pour afficher des bytes en String.
    C'est ce que je fais lignes 342 et 343 (et j'ai aussi testé cette méthode d'affichage à la fin de ma méthode decryption), et cela affiche pourtant toujours des Bytes (incompréhensible pour ma part, et qui n'est pas ce qui est demandé).

    Cette méthode decryption récupère d'abord l'ensemble des bytes du fichier (avec la méthode readBytesFromFile), puis, sépare en paquets de 200 bytes ce contenu, afin d'éviter les problèmes de dépassements de RSA.
    Puis, je cherche à décrypter chaque paquet ainsi obtenu, puis à concaténer ces décriptions.

    J'ai pensé à utiliser un cryptage AES et à crypter cette clé de session avec RSA (comme proposé quelque part sur ce forum) cependant, il est clairement spécifié que je ne dois utiliser QUE le cryptage RSA.

    Merci pour votre aide!

  4. #4
    Membre averti
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    250
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2011
    Messages : 250
    Points : 403
    Points
    403
    Par défaut
    Peux-t-être un problème de taille de byte[], il me semble que lorsque tu cryptes tu passes la taille de la ligne récupéré du fichier (line.getBytes()) et lorsque tu décryptes tu passes un bloc de taille 200.

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Points : 5
    Points
    5
    Par défaut
    Il faudrait donc que je lise également des blocs 200 bytes lors de la lecture pour le cryptage?

    Je n'étais pas sur de ma démarche de couper en blocs puis de crypter/décrypter chaque bloc et de concaténer le résultat. Est-ce que cela est possible?


    Je vais essayer de lire par bloc également de ce pas!
    Merci beaucoup!

  6. #6
    Modérateur
    Avatar de kolodz
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2008
    Messages
    2 211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 211
    Points : 8 316
    Points
    8 316
    Billets dans le blog
    52
    Par défaut
    La découpe peut-être fait sans aucuns problème.

    Normalement, tu as le flux suivant :
    String->byte[X]->y*byte[200]--(cryptage)-->y*byte[200+n]

    y*byte[200+n]--(décrytage)-->y*byte[200]-->byte[X]->String

    Je ne suis plus sûr pour le n. Mais encore de mémoire, c'est l'amorce du cryptage !?

    Si mon flux ne corresponds pas. Essais de faire le tiens pour bien voir la logique interne.

    Cordialement,
    Patrick kolodziejczyk.
    Si une réponse vous a été utile pensez à
    Si vous avez eu la réponse à votre question, marquez votre discussion
    Pensez aux FAQs et aux tutoriels et cours.

  7. #7
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Points : 5
    Points
    5
    Par défaut
    Bonjour!

    Je pense que le flux suggéré kolodz correspond bien à ce que j'applique dans mon algorithme.

    J'ai donc essayé de lire le fichier de départ de la même manière que pour la décryption, comme suggéré :
    (Je ne mets que les méthodes intéressantes)

    J'ai changé le mode du Cipher de "RSA/ECB/NoPadding" en "RSA".
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    private static byte[] rsaDecryption(byte[] crypteddata, PrivateKey privateKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
            Cipher cipher = Cipher.getInstance("RSA");
            cipher.init(Cipher.DECRYPT_MODE, privateKey);
            return cipher.doFinal(crypteddata);
        }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    private static byte[] rsaEncryption(byte[] data, PublicKey publicKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
            Cipher cipher = Cipher.getInstance("RSA");
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            return cipher.doFinal(data); //Encrypte data avec le cipher, tel qu'il a été paramétré, ici en mode RSA, en encryption, encryption qui va utiliser la clé publique.
        }
    A priori, cela est bien encrypté, j'ai déjà testé le décryptage de chaque paquet séparé en appelant la méthode rsaDecryption et en affichant le résultat, cela affiche un bon résultat.
    C'est maintenant dans la méthode de décryption que j'ai un soucis.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    public static byte[] decryption(Path file, PrivateKey privateKey) throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, IOException {
            byte[] crypteddata = readBytesInFile(file); //lecture des bytes du fichier spécifié
            int offset = 0;
            byte[] decryptedfile = null;
     
            //Parcours de tous les bytes du fichier
            while (offset < crypteddata.length) {
                byte[] outputBytes;
                byte[] tmp;
     
                //Si il reste moins de 200 bytes
                if(crypteddata.length - offset < 200 ) {
                    //Copie du contenu restant de crypteddata dans outputBytes
                    outputBytes = new byte[crypteddata.length - offset];
                    System.arraycopy(crypteddata, offset, outputBytes, 0, crypteddata.length - offset);
     
                    //Decryptage de la partie de bytes
                    byte[] decrypt = rsaDecryption(outputBytes, privateKey);
                    String s = new String(decrypt);
                    System.out.println(s);
     
                    //Update de la taille pour recevoir la concaténation
                    tmp = decryptedfile;
                    if (tmp != null) {
                        decryptedfile = new byte[tmp.length + decrypt.length];
                    }
                    else decryptedfile = new byte[decrypt.length];
     
                    //Concaténation des bytes décryptés
                    if (tmp != null) {
                        System.arraycopy(tmp, 0, decryptedfile, 0, tmp.length);
                        System.arraycopy(decrypt, 0, decryptedfile, tmp.length, decrypt.length);
                    }
                    else {
                        System.arraycopy(decrypt, 0, decryptedfile, 0, decrypt.length);
                    }
                    break;
                }
     
                //Création de la partie de bytes, et copie du contenu de crypteddata de offset à offset+200 et mise dans outputBytes de 0 à 200
                outputBytes = new byte[200];
                System.arraycopy(crypteddata, offset, outputBytes, 0, 200);
     
                //Decryptage de la partie de bytes
                byte[] decrypt = rsaDecryption(outputBytes, privateKey);
                String s = new String(decrypt);
                System.out.println(s);
     
                //Update de la taille pour recevoir la concaténation
                tmp = decryptedfile;
                if (tmp != null) {
                    decryptedfile = new byte[decrypt.length + tmp.length];
                }
                else decryptedfile = new byte[decrypt.length];
     
                //Concaténation dans decryptedfile de la partie de bytes
                if (tmp != null) {
                    System.arraycopy(tmp, 0, decryptedfile, 0, tmp.length);
                    System.arraycopy(decrypt, 0, decryptedfile, tmp.length, decrypt.length);
                }
                else {
                    System.arraycopy(decrypt, 0, decryptedfile, 0, decrypt.length);
                }
                offset +=200 ;
            }
            return decryptedfile;
        }
    A cette ligne ci : byte[] decrypt = rsaDecryption(outputBytes, privateKey);
    Je jette javax.crypto.BadPaddingException: Data must start with zero.

    Est-ce que cela peut provenir d'une mauvaise écriture dans le fichier passagé?
    J'utilise cette méthode dans le main pour écrire le contenu de byte[] cryptés :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    //Cryptage
                    byte[] crypt = encryption(Paths.get("file"), keyPair.getPublic());
     
                    //Inscription dans le fichier (même systeme pour DriveUtil)
                    Files.write(Paths.get("cryptedfile"), crypt, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
     
                    //Decryptage
                    uncrypt = decryption(Paths.get("cryptedfile"), keyPair.getPrivate());
    Si ce n'est pas le cas, je ne comprends pas pourquoi...
    Je sais que ma méthode de lecture de bytes dans un fichier marche ; elle est testée et marche pour l'encryption.
    Cependant, pour la décryption, je ne comprends pas ce qu'il se passe...



    Au cas où, le code complet :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    package com.bodom.ghosty;
     
    import javax.crypto.BadPaddingException;
    import javax.crypto.Cipher;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.NoSuchPaddingException;
    import java.io.*;
    import java.math.BigInteger;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.nio.file.StandardOpenOption;
    import java.security.*;
    import java.security.spec.InvalidKeySpecException;
    import java.security.spec.RSAPrivateKeySpec;
    import java.security.spec.RSAPublicKeySpec;
     
    public class EncryptionUtil {
     
        /**
         * Generate a pair of RSA keys
         *
         * @return A keypair of RSA keys
         * @throws NoSuchAlgorithmException
         */
        public static KeyPair keyGenerate() throws NoSuchAlgorithmException {
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(2048);
            return keyGen.genKeyPair();
        }
     
     
        /**
         * Crypt data
         *
         * @param data      Data to encrypt
         * @param publicKey PublicKey used to crypt
         * @return          The crypted data
         * @throws NoSuchAlgorithmException
         * @throws NoSuchPaddingException
         * @throws InvalidKeyException
         * @throws IllegalBlockSizeException
         * @throws BadPaddingException
         */
        private static byte[] rsaEncryption(byte[] data, PublicKey publicKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
            Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            return cipher.doFinal(data);
        }
     
     
     
        /**
         * Read the bytes of a file
         *
         * @param file is the file to read
         * @return     the bytes of the file
         * @throws IOException
         */
        private static byte[] readBytesInFile (Path file) throws IOException {
            byte[] result = new byte[(int)Files.size(file)];
            try {
                try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file.getFileName().toString()))) {
                    int bytesRead = 0;
                    while (bytesRead < result.length) {
                        int bytesLeft = result.length - bytesRead;
                        int bytesGet = inputStream.read(result, bytesRead, bytesLeft);
                        if (bytesGet > 0) {
                            bytesRead += bytesGet;
                        }
                    }
                }
            } catch (IOException e) {
                System.out.println(e);
            }
            return result;
        }
     
     
        /**
         * Encrypt a file
         *
         * @param file      Path of the file to crypt
         * @param publicKey PublicKey used to crypt the file
         * @return          A byte array which contains the crypted lines of the file
         * @throws java.io.IOException
         * @throws javax.crypto.IllegalBlockSizeException
         * @throws java.security.InvalidKeyException
         * @throws javax.crypto.BadPaddingException
         * @throws java.security.NoSuchAlgorithmException
         * @throws javax.crypto.NoSuchPaddingException
         */
        public static byte[] encryption (Path file,  PublicKey publicKey) throws IOException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
            byte[] datatocrypt = readBytesInFile(file); //lecture des bytes du fichier spécifié
            int offset = 0;
            byte[] cryptedfile = null;
     
            //JUSQUE ICI BONNE RECUPERATION DANS LE FICHIER
     
            //Parcours de tous les bytes du fichier
            while (offset < datatocrypt.length) {
                byte[] outputBytes;
                byte[] tmp;
     
                //Si il reste moins de 200 bytes
                if(datatocrypt.length - offset < 200 ) {
                    //Copie du contenu restant de datatocrypt dans outputBytes
                    outputBytes = new byte[datatocrypt.length - offset];
                    System.arraycopy(datatocrypt, offset, outputBytes, 0, datatocrypt.length - offset);
     
                    //Cryptage de la partie de bytes
                    byte[] crypt = rsaEncryption(outputBytes, publicKey);
     
                    //Update de la taille pour recevoir la concaténation
                    tmp = cryptedfile;
                    if (tmp != null) {
                        cryptedfile = new byte[tmp.length + crypt.length];
                    }
                    else cryptedfile = new byte[crypt.length];
     
                    //Concaténation des bytes cryptés
                    if (tmp != null) {
                        System.arraycopy(tmp, 0, cryptedfile, 0, tmp.length);
                        System.arraycopy(crypt, 0, cryptedfile, tmp.length, crypt.length);
                    }
                    else {
                        System.arraycopy(crypt, 0, cryptedfile, 0, crypt.length);
                    }
                    break;
                }
     
                //Création de la partie de bytes, et copie du contenu de datatocrypt de offset à offset+200 et mise dans outputBytes de 0 à 200
                outputBytes = new byte[200];
                System.arraycopy(datatocrypt, offset, outputBytes, 0, 200);
     
                //Cryptage de la partie de bytes
                byte[] crypt = rsaEncryption(outputBytes, publicKey);
     
                //Update de la taille pour recevoir la concaténation
                tmp = cryptedfile;
                if (tmp != null) {
                    cryptedfile = new byte[tmp.length + crypt.length];
                }
                else cryptedfile = new byte[crypt.length];
     
                //Concaténation dans cryptedfile de la partie de bytes
     
                if (tmp != null) {
                    System.arraycopy(tmp, 0, cryptedfile, 0, tmp.length);
                    System.arraycopy(crypt, 0, cryptedfile, tmp.length, crypt.length);
                }
                else {
                    System.arraycopy(crypt, 0, cryptedfile, 0, crypt.length);
                }
     
                offset += 200 ;
            }
            return cryptedfile;
        }
     
     
        /**
         * Decrypt data
         *
         * @param crypteddata Crypted data to decrypt
         * @param privateKey  PrivateKey used to decrypt
         * @return            The decrypted data
         * @throws NoSuchAlgorithmException
         * @throws NoSuchPaddingException
         * @throws InvalidKeyException
         * @throws IllegalBlockSizeException
         * @throws BadPaddingException
         */
        private static byte[] rsaDecryption(byte[] crypteddata, PrivateKey privateKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
            Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
            cipher.init(Cipher.DECRYPT_MODE, privateKey);
            return cipher.doFinal(crypteddata);
        }
     
     
        /**
         * Decrypt a file
         *
         * @param file       Path of the file to decrypt
         * @param privateKey PrivateKey used to decrypt the file
         * @return           A byte array which contains the decrypted lines of the file
         * @throws IOException
         * @throws IllegalBlockSizeException
         * @throws InvalidKeyException
         * @throws BadPaddingException
         * @throws NoSuchAlgorithmException
         * @throws NoSuchPaddingException
         */
        public static byte[] decryption(Path file, PrivateKey privateKey) throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, IOException {
            byte[] crypteddata = readBytesInFile(file); //lecture des bytes du fichier spécifié
            int offset = 0;
            byte[] decryptedfile = null;
     
            //Parcours de tous les bytes du fichier
            while (offset < crypteddata.length) {
                byte[] outputBytes;
                byte[] tmp;
     
                //Si il reste moins de 200 bytes
                if(crypteddata.length - offset < 200 ) {
                    //Copie du contenu restant de crypteddata dans outputBytes
                    outputBytes = new byte[crypteddata.length - offset];
                    System.arraycopy(crypteddata, offset, outputBytes, 0, crypteddata.length - offset);
     
                    //Decryptage de la partie de bytes
                    byte[] decrypt = rsaDecryption(outputBytes, privateKey);
                    String s = new String(decrypt);
                    System.out.println(s);
     
                    //Update de la taille pour recevoir la concaténation
                    tmp = decryptedfile;
                    if (tmp != null) {
                        decryptedfile = new byte[tmp.length + decrypt.length];
                    }
                    else decryptedfile = new byte[decrypt.length];
     
                    //Concaténation des bytes décryptés
                    if (tmp != null) {
                        System.arraycopy(tmp, 0, decryptedfile, 0, tmp.length);
                        System.arraycopy(decrypt, 0, decryptedfile, tmp.length, decrypt.length);
                    }
                    else {
                        System.arraycopy(decrypt, 0, decryptedfile, 0, decrypt.length);
                    }
                    break;
                }
     
                //Création de la partie de bytes, et copie du contenu de crypteddata de offset à offset+200 et mise dans outputBytes de 0 à 200
                outputBytes = new byte[200];
                System.arraycopy(crypteddata, offset, outputBytes, 0, 200);
     
                //Decryptage de la partie de bytes
                byte[] decrypt = rsaDecryption(outputBytes, privateKey);
                String s = new String(decrypt);
                System.out.println(s);
     
                //Update de la taille pour recevoir la concaténation
                tmp = decryptedfile;
                if (tmp != null) {
                    decryptedfile = new byte[decrypt.length + tmp.length];
                }
                else decryptedfile = new byte[decrypt.length];
     
                //Concaténation dans decryptedfile de la partie de bytes
                if (tmp != null) {
                    System.arraycopy(tmp, 0, decryptedfile, 0, tmp.length);
                    System.arraycopy(decrypt, 0, decryptedfile, tmp.length, decrypt.length);
                }
                else {
                    System.arraycopy(decrypt, 0, decryptedfile, 0, decrypt.length);
                }
                offset +=200 ;
            }
            return decryptedfile;
        }
     
        /**
         * Save a key in a file
         *
         * @param modulus  Modulus of the key to save
         * @param exponent Exponent of the key to save
         * @param filename File used to save the keys
         * @throws IOException
         * @throws NoSuchAlgorithmException
         */
        private static void saveKeyToFile (BigInteger modulus, BigInteger exponent, String filename) throws IOException, NoSuchAlgorithmException {
            try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename)))) {
                objectOutputStream.writeObject(modulus);
                objectOutputStream.writeObject(exponent);
            }
        }
     
        /**
         * Save a KeyPair in two files
         *
         * @param keyPair KeyPair to save
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         * @throws FileNotFoundException
         * @throws IOException
         */
        public static void saveKeyPair(KeyPair keyPair) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
     
            RSAPublicKeySpec rsaPublicKeySpec = keyFactory.getKeySpec(keyPair.getPublic(), RSAPublicKeySpec.class);
            saveKeyToFile(rsaPublicKeySpec.getModulus(), rsaPublicKeySpec.getPublicExponent(), "keys/public.key");
     
            RSAPrivateKeySpec rsaPrivateKeySpec = keyFactory.getKeySpec(keyPair.getPrivate(), RSAPrivateKeySpec.class);
            saveKeyToFile(rsaPrivateKeySpec.getModulus(), rsaPrivateKeySpec.getPrivateExponent(), "keys/.private.key");
        }
     
        /**
         * Get a PublicKey from a file
         *
         * @param filename File where the PublicKey is saved
         * @return         The PublicKey get in the file
         * @throws IOException
         * @throws ClassNotFoundException
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         */
        private static PublicKey getPublicKeyFromFile (String filename) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
            try (ObjectInputStream objectInputStream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
                BigInteger modulus = (BigInteger) objectInputStream.readObject();
                BigInteger exponent = (BigInteger) objectInputStream.readObject();
     
                RSAPublicKeySpec rsaPublicKeySpec = new RSAPublicKeySpec(modulus, exponent);
                KeyFactory keyFactory = KeyFactory.getInstance("RSA");
                return keyFactory.generatePublic(rsaPublicKeySpec);
            }
        }
     
        /**
         * Get a PrivateKey from a file
         *
         * @param filename File where the PrivateKey is saved
         * @return         The PrivateKey get in the file
         * @throws IOException
         * @throws ClassNotFoundException
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         */
        private static PrivateKey getPrivateKeyFromFile (String filename) throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException {
            try (ObjectInputStream objectInputStream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(filename)))) {
                BigInteger modulus = (BigInteger) objectInputStream.readObject();
                BigInteger exponent = (BigInteger) objectInputStream.readObject();
     
                RSAPrivateKeySpec rsaPrivateKeySpec = new RSAPrivateKeySpec(modulus, exponent);
                KeyFactory keyFactory = KeyFactory.getInstance("RSA");
                return keyFactory.generatePrivate(rsaPrivateKeySpec);
            }
        }
     
        /**
         * Get the RSA keypair from the files
         *
         * @return The Keypair which contains the public and the private key
         * @throws IOException
         * @throws ClassNotFoundException
         * @throws NoSuchAlgorithmException
         * @throws InvalidKeySpecException
         */
        public static KeyPair getKeysFromFiles () throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException{
            PublicKey publicKey = getPublicKeyFromFile("keys/public.key");
            PrivateKey privateKey = getPrivateKeyFromFile("keys/.private.key");
            return new KeyPair(publicKey, privateKey);
        }
     
        public static void main(String[] args) throws InvalidKeySpecException, NoSuchAlgorithmException {
            // Initialization MARCHE
            KeyPair kp = null;
            try {
                kp = EncryptionUtil.keyGenerate();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
     
            //Saving keys part MARCHE
            try {
                saveKeyPair(kp);
            } catch (NoSuchAlgorithmException | InvalidKeySpecException| IOException e) {
                System.out.println("Error during the storage of the keys : " + e);
            }
     
            //Getting keys part MARCHE
            KeyPair keyPair = null;
     
            try {
                keyPair = getKeysFromFiles();
            } catch (ClassNotFoundException | NoSuchAlgorithmException | InvalidKeySpecException | IOException e) {
                System.out.println("Error during the loading of the keys : " + e);
            }
     
            // Crypt part
            byte[] uncrypt;
            try {
                if (keyPair != null) {
                    //Cryptage
                    byte[] crypt = encryption(Paths.get("file"), keyPair.getPublic());
     
                    //Inscription dans le fichier (même systeme pour DriveUtil)
                    Files.write(Paths.get("cryptedfile"), crypt, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
     
                    //Decryptage
                    uncrypt = decryption(Paths.get("cryptedfile"), keyPair.getPrivate());
     
                    String v = new String(uncrypt);
                    System.out.println(v);
                }
            } catch (InvalidKeyException | NoSuchAlgorithmException
                    | NoSuchPaddingException | IllegalBlockSizeException
                    | BadPaddingException | IOException e) {
                System.out.println(e);
            }
        }
    }
    Je ne comprends plus rien ><
    J'ai une exception qui pète dès que j'utilise "RSA" ou "RSA/ECB/PKCS1Padding" pour initialiser le buffer, l'exception est la suivante : javax.crypto.BadPaddingException: Data must start with zero.
    Et quand j'utilise "RSA/ECB/NoPadding", je fais tout le parcourt sans erreur, mais aucune décryption n'est effectuée...

    C'est assez urgent, si vous pouviez m'aider ce serait simplement génial.
    Merci d'avance pour votre aide et vos conseils!

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 5
    Points : 5
    Points
    5
    Par défaut
    Problème résolu.
    C'était un problème de taille des blocs en entrées en sorties des phases d'encryption et de décryption.
    Merci pour votre aide!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Cryptage / Décryptage ( RSA-MD2 )
    Par Shirase_Akira dans le forum Langage
    Réponses: 0
    Dernier message: 17/12/2012, 13h24
  2. Algorithme de cryptage décryptage RSA
    Par ISIL3EME dans le forum Sécurité
    Réponses: 4
    Dernier message: 26/07/2010, 15h22
  3. Problème de cryptage/décryptage RSA en Java
    Par Reeter dans le forum Sécurité
    Réponses: 2
    Dernier message: 29/03/2009, 22h41
  4. [Hibernate&POA] Cryptage et Décryptage
    Par godofchips dans le forum Hibernate
    Réponses: 1
    Dernier message: 23/05/2007, 17h10
  5. [VB.net] Cryptage et décryptage
    Par WriteLN dans le forum Windows Forms
    Réponses: 1
    Dernier message: 06/04/2006, 10h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo