Bonjour, j'ai en ensemble client/serveur qui font un handshake en asymétrique pour obtenir une clé symétrique (clé de session donc). tout tourne parfaitement sauf pour les paquet un peu volumineux (500bytes style) du coups j'ai modifié mon crypt en utilisant les update pour crypter block par block.
seulement j'obtiens maintenant une erreur étrange.
pas si étrange? quand je l'ai vu je me suis dit: bah c'est rien, un petit new oublié quelque part...
Code : Sélectionner tout - Visualiser dans une fenêtre à part java.lang.NullPointerException
mais en debug quand je mets un break sur la ligne concerné je n'ai aucune valeur a null et pire, le code fonctionne.
-> il ne fonctionne pas en exécution normal
-> il fonctionne en pas a pas
voila le code:
j'insiste sur le fait que ma clé session est bonne, si je ne passe pas dans la boucle (donc petit paquet) mon byte[] est bien crypté et décrypté coté serveur.
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 public byte[] doCrypt(byte[] mess) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException , IOException { int off = 0; byte[] temp = new byte[encrypt.getBlockSize()]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while(mess.length - off > encrypt.getBlockSize()) { System.arraycopy(mess, off, temp, 0, encrypt.getBlockSize()); bos.write(encrypt.update(temp)); off += encrypt.getBlockSize(); } System.arraycopy(mess, off, temp, 0, mess.length - off); bos.write(encrypt.doFinal(temp)); return bos.toByteArray(); } public byte[] doDecrypt(byte[] mess) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException { int off = 0; byte[] temp = new byte[decrypt.getBlockSize()]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while(mess.length - off > decrypt.getBlockSize()) { System.arraycopy(mess, off, temp, 0, decrypt.getBlockSize()); bos.write(decrypt.update(temp)); off += decrypt.getBlockSize(); } System.arraycopy(mess, off, temp, 0, decrypt.getBlockSize()); bos.write(decrypt.doFinal(temp)); return bos.toByteArray(); }
si quelqu'un a une idée... j'ai pensé a un problème d'accès concurrent mais il n'y a qu'un thread... le main.
ps: null pointer sur la ligne en rouge
Partager