Bonjour,
je ne sais pas si je suis dans le bon forum, mais je me lance :
est-ce possible d'utiliser mcrypt (librairie de chiffrage) avec java et comment ?
merci
Version imprimable
Bonjour,
je ne sais pas si je suis dans le bon forum, mais je me lance :
est-ce possible d'utiliser mcrypt (librairie de chiffrage) avec java et comment ?
merci
Bonjour,
mcrypt pour php ?
C'est certainnement du code natif. Donc oui c'est possible mais un peu lourd à coup de JNI.
En java il y a surtout l'api BouncyCastle simple et beacoup plus rapide.
Merci pour ta réponse rapide.
je doit crypter des paramètres de lien, et envoyer ça sous forme hexa, seulement le lien générer c'est vers un site php, donc la personne ou ma page va etre rediriger travail avec php, il va decrypter le lien avec mcrypt
est-ce possible d'utiliser different api ?
merci
Ca dépend vous voulez utiliser quoi comme algo de chiffrement ?
rijndael-128
Donc AES-128 pour Java, c'est standard pour Java pas la peine de provider externe.
Il faut essayer , je ne sais pas si les implémentations sont identiques.
Il suffit qu'ils n'aient pas utilisé les même S-Box et ça ne marchera pas.
C'est resoulu, pour ceux qui ont besoin :
Code:
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 public static byte[] encryptJSONStringToBytes(String pSecretKey, String pSecretMsg) { byte[] result = null; if (StringUtil.isNotEmpty(pSecretKey) && StringUtil.isNotEmpty(pJsonString)) { try { byte[] keyData = pSecretKey.getBytes(); SecretKeySpec key = new SecretKeySpec(keyData, "AES"); IvParameterSpec ivSpec = new IvParameterSpec("ton vecteur".getBytes()); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // The String is padded with the good size. String chaineToEncryp = new String(pSecretMsg); int blocksize = cipher.getBlockSize(); int remainder = chaineToEncryp.length() % blocksize; if (remainder > 0) { chaineToEncryp = StringUtils.rightPad(chaineToEncryp, chaineToEncryp.length() - remainder + blocksize); } result = cipher.doFinal(chaineToEncryp.getBytes()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } } return result; }
Bravo !