J'ai les routines de cryptage/décryptage suivantes et j'ai besoin de les porter sur mon projet BlackBerry. Pouvez-vous s'il vous plaît me faire commencer?Code de cryptage Port Java-SE pour BlackBerry
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
public String EncryptData(String data, String skey) throws Exception {
String encryptedData = "";
try{
byte [] bData = data.getBytes();
String alg = "AES/ECB/NoPadding";
SecretKey key = new SecretKeySpec(skey.getBytes(), alg.replaceFirst("/.*", ""));
Cipher cipher = Cipher.getInstance(alg);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoded = cipher.doFinal(bData);
encryptedData = bytesToHex(encoded);
}
catch(Exception e){
throw e;
}
return encryptedData;
}
public String DecryptData(String hexString, String skey) throws Exception {
String decryptedData = "";
try{
byte [] bData = convToBinary(hexString);
String alg = "AES/ECB/NoPadding";
SecretKey key = new SecretKeySpec(skey.getBytes(), alg.replaceFirst("/.*", ""));
Cipher cipher = Cipher.getInstance(alg);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decoded = cipher.doFinal(bData);
decryptedData = new String(decoded);
}
catch(Exception e){
throw e;
}
return decryptedData;
}
Quel est exactement votre problème? – malaverdiere
On dirait que vous avez déjà commencé. –
Les méthodes énumérées ci-dessus fonctionnent parfaitement dans mon application Java. Mais ne compile pas dans Blackberry. J'ai essayé d'importer les namspaces cryptographiques pertinents (net.rim.device.api.crypto. *). Mais aucun ne semble correspondre à ma mise en œuvre ci-dessus. Je dois déchiffrer les données qui existent dans un fichier et utiliser les mêmes algorithmes. – JDeVil