Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1420 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  De java a c++ ou VB.net

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

De java a c++ ou VB.net

n°2269309
ogst
Posté le 08-11-2015 à 19:57:24  profilanswer
 

Bonjours a tous je suis un debutant dans la programation en java mais me debrouille plutot bien en C++ et en visual basic donc si je vous écrit aujourd'hui c'est pour savoir si quelqu'un pourrat me tranformer cette algorithme de cryptage codée en java en une method en c++ ou VB.net de préference merci d'avance
 
 
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
 
public class b
{
  static char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
  private String iv = "2367657EQH3dqzTF";
  private IvParameterSpec ivspec = new IvParameterSpec(this.iv.getBytes());
  private SecretKeySpec keyspec = new SecretKeySpec(this.SecretKey.getBytes(), "AES" );
  private Cipher cipher;
  private String SecretKey = "rdsjyfl3573f57fZ";
   
  public b()
  {
    try
    {
      this.cipher = Cipher.getInstance("AES/CBC/NoPadding" );
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      localNoSuchAlgorithmException.printStackTrace();
    }
    catch (NoSuchPaddingException localNoSuchPaddingException)
    {
      localNoSuchPaddingException.printStackTrace();
    }
  }
   
  public byte[] encrypt(String paramString)
    throws Exception
  {
    if ((paramString == null) || (paramString.length() == 0)) {
      throw new Exception("Empty string" );
    }
    byte[] arrayOfByte = null;
    try
    {
      this.cipher.init(1, this.keyspec, this.ivspec);
      arrayOfByte = this.cipher.doFinal(a(paramString).getBytes());
    }
    catch (Exception localException)
    {
      throw new Exception("[encrypt] " + localException.getMessage());
    }
    return arrayOfByte;
  }
   
  public static String bytesToHex(byte[] paramArrayOfByte)
  {
    char[] arrayOfChar = new char[2 * paramArrayOfByte.length];
    for (int i = 0; i < paramArrayOfByte.length; i++)
    {
      arrayOfChar[(2 * i)] = HEX_CHARS[((paramArrayOfByte[i] & 0xF0) >>> 4)];
      arrayOfChar[(2 * i + 1)] = HEX_CHARS[(paramArrayOfByte[i] & 0xF)];
    }
    return new String(arrayOfChar);
  }
   
  public static byte[] hexToBytes(String paramString)
  {
    if (paramString == null) {
      return null;
    }
    if (paramString.length() < 2) {
      return null;
    }
    int i = paramString.length() / 2;
    byte[] arrayOfByte = new byte[i];
    for (int j = 0; j < i; j++) {
      arrayOfByte[j] = ((byte)Integer.parseInt(paramString.substring(j * 2, j * 2 + 2), 16));
    }
    return arrayOfByte;
  }
   
  private static String a(String paramString)
  {
    char c = '\000';
    int i = 16;
    int j = paramString.length() % i;
    int k = i - j;
    for (int m = 0; m < k; m++) {
      paramString = paramString + c;
    }
    return paramString;
  }
}

mood
Publicité
Posté le 08-11-2015 à 19:57:24  profilanswer
 

n°2269371
TotalRecal​l
Posté le 09-11-2015 à 14:49:25  profilanswer
 

C'est de l'AES CBC avec la clé et l'IV en dur dans ton code. Donc un truc très standard.
Le reste de ton code est trop moche pour que j'aie envie de le comprendre en plus de n'être appelé nulle part.

 

Commence par là, la question a l'air très proche de ton cas à première vue :
http://stackoverflow.com/questions [...] p-and-java
La conversion C#->VB est triviale, comme ça tu auras au moins un début de qqch à proposer.

 

Si tu veux du C++ c'est une autre histoire selon les libs auxquelles tu as accès.

 

Je m'interroge : porter un algo de cryptage d'un langage à un autre pour faire communiquer deux applis est un besoin commun, mais pourquoi C++ OU vb ? Tu veux juste un algo AES ou bien tu dois reproduire un truc particulier de cette implémentation ?


Message édité par TotalRecall le 09-11-2015 à 14:52:02

---------------
Réalisation amplis classe D / T      Topic .Net - C# @ Prog

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  De java a c++ ou VB.net

 

Sujets relatifs
JAVA - Distribution d'un paquet de carteJAVA - Distribution d'un jeu de carte
Besoin d'aide pour programme sous Java's Cool !Appel concurent de procedure stocké oracle dans mon programme java
[java] cherche aide sur getters setterssimulation d'un systeme d'exploitation en java
[java]comment compter les cases identique d'un tableau ?Java map vers Javascript map ?
Recherche développeur FullStack Java/AngularJspropriétés des objets java (en nombre de bits )
Plus de sujets relatifs à : De java a c++ ou VB.net


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR