Giz | Bonjour,
Je dispose de 2 applets java séparées.
-La première génère un hash MD5 d'un fichier puis signe ce hash avec l'algo "MD5withRSA" en utilisant la clé privée lue à partir d'un certificat (fichier au format PKCS#12). Un fichier .sig est généré.
-La deuxième lit le fichier .sig, décrypte la signature avec l'algorithme "RSA" pour pouvoir lire le hash MD5.
Le problème se pose lors du décryptage de la signature. Un bout de code :
Code :
- // Obtain an object to perform encryption or decryption
- Cipher cipher = Cipher.getInstance("RSA", provBC);
- // Initialize the cipher object for decryption
- cipher.init(Cipher.DECRYPT_MODE, cert.getPublicKey());
- // Now decrypt data
- System.out.println("sig len : " + sig.length);
- plainText = new byte[cipher.getOutputSize(sig.length)];
- byte[] pText1 = new byte[127];
- byte[] pText2 = new byte[127];
- byte[] pText3 = new byte[127];
- byte[] pText4 = new byte[127];
- System.out.println("plain text needed len = " + plainText.length);
- int ptLen1 = cipher.update(sig, 0, 54, pText1);
- int ptLen2 = cipher.update(sig, 54, 54, pText2);
- int ptLen3 = cipher.update(sig, 108, 54, pText3);
- int ptLen4 = cipher.update(sig, 162, 55, pText4);
- System.out.println("plain text len1 = " + ptLen1);
- System.out.println("plain text len2 = " + ptLen2);
- System.out.println("plain text len3 = " + ptLen3);
- System.out.println("plain text len4 = " + ptLen4);
- plainText = cipher.doFinal();
- for (int i = 0; i < ptLen1; i++)
- plainText[i] = pText1[i];
- for (int i = 0; i < ptLen2; i++)
- plainText[ptLen1+i] = pText2[i];
- for (int i = 0; i < ptLen3; i++)
- plainText[ptLen1+ptLen2+i] = pText3[i];
- for (int i = 0; i < ptLen4; i++)
- plainText[ptLen1+ptLen2+ptLen3+i] = pText4[i];
- System.out.println("plain text content = " + new String(plainText));
|
Ce code ne marche pas ! L'erreur est : too much data for RSA block
causée à la ligne "int ptLen3 = ..."
Question :
D'où vient l'erreur ?
Décrypter en multipartie requiert-il d'encrypter (signer dans mon cas) en multipartie ?
Comment décrypter en multipartie une signature avec RSA ?
Merci .
N.B. : tout exemple de code est bienvenue...je poursuis mes recherches sur google. Message édité par Giz le 29-03-2007 à 11:04:24
|