Bonjour,
Actuellement dans la rubrique officielle de Bouncy Castle section Documentation : http://www.bouncycastle.org/fr/documentation.html , ils indiquent clairement :
De quels packages parlent-ils ? Où donc se situent-ils ?Vous pourrez trouver des programmes de tests dans les packages :
org.bouncycastle.crypto.test
org.bouncycastle.jce.provider.test
org.bouncycastle.cms.test
org.bouncycastle.mail.smime.test
org.bouncycastle.openpgp.test
org.bouncycastle.tsp.test
Ici http://www.cs.berkeley.edu/~jonah/bc...w-summary.html il n'y a qu'une liste des méthodes et des classes.
Quant à leurs exemples qu'on est censé voir sur une page comme celle ci : http://www.cs.berkeley.edu/~jonah/bc...12Example.html mais il n'y a selon moi rien de concret.
N'ayant pas l'habitude de développer en Java, j'imagine que je suis à côté de la plaque mais j'en viens à imaginer que c'est dans le .jar d'installation de la librairie ou un truc comme ça.
Quelqu'un saurait-il me guider un peu ?
Un dernier exemple : http://javadox.com/org.bouncycastle/...nt.KeyGen.html
Il n'y pas de descriptif de fonction, pas d'indication sur les parametres attendus...
Pour être vraiment précis (donc ce lien ne me suffit pas : http://nyal.developpez.com/tutoriel/java/bouncycastle/) je cherche une implémentation de l'algorithme de chiffrement Serpent en 256 bits.
Actuellement j'ai ce bout de code :
Il fonctionne à un détail près : je peux changer la valeur de keyLength de 1 à 256 mais mon cypher reste toujours identique.
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 import java.security.SecureRandom; import java.security.Security; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; public class Cortex { private static final String salt = "blabla plein de sel"; private static final int iterations = 66000; private static final int keyLength = 256; private static final SecureRandom random = new SecureRandom(); public static void main(String [] args) throws Exception { Security.insertProviderAt(new BouncyCastleProvider(), 1); String passphrase = "blabla la passphrase"; String plaintext = "hello worldhello worldhello worldhello worldhello worldhello worldhello world"; byte [] ciphertext = encrypt(passphrase, plaintext); System.out.print("cipher: "); for (int i=0; i < ciphertext.length; i++) System.out.print(new Integer(ciphertext[i])+" "); System.out.println(""); String recoveredPlaintext = decrypt(passphrase, ciphertext); System.out.println(recoveredPlaintext); } private static byte [] encrypt(String passphrase, String plaintext) throws Exception { SecretKey key = generateKey(passphrase); Cipher cipher = Cipher.getInstance("SERPENT/CTR/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, key, random); return cipher.doFinal(plaintext.getBytes()); } private static String decrypt(String passphrase, byte [] ciphertext) throws Exception { SecretKey key = generateKey(passphrase); Cipher cipher = Cipher.getInstance("SERPENT/CTR/NOPADDING"); cipher.init(Cipher.DECRYPT_MODE, key, random); return new String(cipher.doFinal(ciphertext)); } private static SecretKey generateKey(String passphrase) throws Exception { PBEKeySpec keySpec = new PBEKeySpec(passphrase.toCharArray(), salt.getBytes(), iterations, keyLength); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWITHSHA256AND256BITAES-CBC-BC"); return keyFactory.generateSecret(keySpec); } }
J'en conclus donc que j'ai vraiment besoin de la doc afin de comprendre les mécaniques sous-jacentes de Bouncy Castle.
Merci d'avance à vous tous.
Partager