title: AES 256 encryption in C++ and Qt 5
body: <p>I have a Java code for encryption in place as follows!</p>
  
  <pre><code>private static byte[] encrypt(byte[] raw, byte[] clear) throws 
     Exception {  
      SecretKeySpec skeySpec = new SecretKeySpec(raw,  "AES");  
      Cipher cipher = null;
  
      if(isIVUsedForCrypto) {
          cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
          cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(IV));  
      }
      else 
      {
          cipher = Cipher.getInstance("AES");
          cipher.init(Cipher.ENCRYPT_MODE, skeySpec);  
      }
      byte[] encrypted = cipher.doFinal(clear);  
      return encrypted;  
  }  
  
   public static byte[] toByte(String hexString) { 
  
      int len = hexString.length()/2;  
      byte[] result = new byte[len];  
      try{
      for (int i = 0; i &lt; len; i++) { 
          result[i] = Integer.valueOf(hexString.substring(2*i, 2*i+2),16).byteValue();  
      }
      }catch (Exception e) {
  
      }
      return result;  
  }  
  
  public static String toHex(byte[] buf) {  
      if (buf == null)  
          return "";  
      StringBuffer result = new StringBuffer(2*buf.length);  
      for (int i = 0; i &lt; buf.length; i++) {  
          appendHex(result, buf[i]);  
      }  
      return result.toString();  
  }  
  private final static String HEX = "0123456789ABCDEF";  
  private static void appendHex(StringBuffer sb, byte b) {  
      sb.append(HEX.charAt((b&gt;&gt;4)&amp;0x0f)).append(HEX.charAt(b&amp;0x0f));  
  }  
  </code></pre>
  
  <p>From Java main method: </p>
  
  <pre><code>  byte[] result = encrypt(toByte(rawKey), plaintext.getBytes());
  </code></pre>
  
  <p>I need to write the C++ equivalent for the above methods (in java). I am not aware of the C++ classes for Cryptography and would like someone to please provide an example showing the same.</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My raw key would be in hexadecimal like -> 729308A8E815F6A46EB3A8AE6D5463CA7B64A0E2E11BC26A68106FC7697E727E</p>
  
  <p>and my final encrypted password is --> 812DCE870D82E93DB62CDA66AAF37FB2</p>
  
  <p>This works in Java but I need a similar solution for C++</p>