J’ai une petite question concernant Chilkat Crypt .NET. En début d’année nous avons acheté ce composant et pour l’instant nous en sommes très satisfait en ce qui concerne l’utilisation sous .NET.
Pour des raisons diverses nous devons maintenant développer certaines de nos applications en Java. J’aimerai en Java, en utilisant la classe javax.crypto, pouvoir décrypter les différentes choses cryptées sous .NET avec votre composant. Pour cela j’ai effectué un petit test. J’ai crypté la même chaînes une fois avec votre composant et l’autre fois avec la classe javax.crypto. Je n’arrive jamais au même résultat et cela m’ennuie beaucoup.
Avez-vous des informations à me donner ou éventuellement une classe Java qui permet de décrypter ce qui a été cryptée en .NET ???
Voilà le code utiliser pour crypter sous .NET :
public string CryptData(string data)
{
Chilkat.Crypt crypt = new Chilkat.Crypt() ;
crypt.UnlockComponent("zzzzzz") ;
crypt.SetAlgorithmBlowfish() ;
crypt.KeyLength = 128 ;
crypt.SetSecretKeyViaPassPhrase("0123456789abcdef") ;
string encryptedDataString = "" ;
byte [] encryptedDataByte ;
encryptedDataByte = crypt.Encrypt(Encoding.Unicode.GetBytes(data)) ;
encryptedDataString = crypt.EncodeBase64(encryptedDataByte) ;
return encryptedDataString ;
}
Voici ma classe en Java :
public class TestBlowFish
{
private final String key="0123456789abcdef";
public TestBlowFish()
{
byte[] encrypted = null;
SecretKeySpec skeySpec=null;
String cryptedB64="";
Try
{
System.out.println("key b64="+Base64.encodeBytes(key.getBytes()));
skeySpec = new SecretKeySpec(key.getBytes(), "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
final String tocrypt = "Test de Cryptage Blowfish";
encrypted = cipher.doFinal(tocrypt.getBytes());
cryptedB64=Base64.encodeBytes(encrypted);
System.out.println("encrypted b64:"+cryptedB64);
byte[] decrypted= null;
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
if(encrypted!=null)
{
decrypted =cipher.doFinal(Base64.decode(cryptedB64));
}
System.out.println("decoded with javax.crypto:"+new String(decrypted));
//decode(encrypted);
}
catch(Exception e)
{
e.printStackTrace();
}
}