title: Leading to same value on Decryption with DESede CBC NoPadding
body: <p>I am asked to verify if the encryption is working ok. I am given input hex text of 238 bytes. Asked to use DESede/CBC/NoPadding algorithm. I am also given encrypted value. Of course, I am given key also ( Given two bytes. Added third byte as copy of first byte to make it three bytes)</p>
  
  <p>(238 bytes+ 2 bytes padding)</p>
  
  <p>Problem is: Encrypted value from my code does not match completely with the given encrypted value ( only First 56 bytes are matching). </p>
  
  <p>What I did is: Decrypted the given encrypted value and encrypted value produced from my code. Both of these decrypted values are matching with the given input.</p>
  
  <p>That means, I have two encrypted values for which the decrypted value is the same. </p>
  
  <p>Using InitialVector of Zeros.(8 zero bytes).</p>
  
  <p>Can somebody throw some light? I am sure I am missing something. Thanks for any help. </p>
  
  <p>Using javax.crypto.Cipher.getInstance for getting Cipher instance. Using SecretKeyFactory and DESedeKeySpec classes to generate key</p>
  
  <p>Edited:</p>
  
  <pre><code>public String encrypt(byte[] sourceDataInBytes, String keyInHex, String cryptoMode, String cryptoPadding)
      {
  Cipher des3cipher = null;
  IvParameterSpec ivParamSpec = null;
  String transformation = "DESede"+"/"+ cryptoMode+"/"+cryptoPadding;
  byte[] encryptedDataInBytes = null;
  try{
      des3cipher = Cipher.getInstance(transformation);
          Key key = generate3DESKey(keyInHex);
      if(cryptoMode.equalsIgnoreCase("CBC"))  
          {
              ivParamSpec = new IvParameterSpec(INITIAL_VECTOR_SALT);
              des3cipher.init(CYPHER_ENCRYPT_MODE, key, (AlgorithmParameterSpec)ivParamSpec );
          }else{
          des3cipher.init(CYPHER_ENCRYPT_MODE, key);
          }
  
          if(cryptoPadding.equals("NoPadding")){'
      sourceDataInBytes = addPadding(sourceDataInBytes, 8);
      }
          encryptedDataInBytes = des3cipher.doFinal(sourceDataInBytes);
      }catch(Exception e){
  e.printStackTrace();
      }
  return encryptedDataInBytes ;
  }
  
  public Key generate3DESKey(String srcInHex)
  {
  Key key = null;
  if(src != null)
  {
      byte[] bk = null;
      try{
          bk = hexStringToByte(src + src.length==32 ? src.substring(0,16) : ""));
  
          DESedeKeySpec des3KeySpec = new DESedeKeySpec(bk);
          SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
          key =  keyFactory.generateSecret(des3KeySpec);
  
      }catch(Exception e){
          e,printStyackTrace();
      }
  
  }
  return key;
  }
  </code></pre>