title: Base64 Decryption with given encryption algorithm (DES base64, secretKey, Cipher)
body: <p>When I encrypt the password <strong>!QAZxdr5</strong> by the code below:</p>
  
  <pre><code>public static String encryptPassword(String msg) {
      try {
          KeySpec keySpec = new DESKeySpec(msg.getBytes());
          SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(keySpec);
          Cipher ecipher = Cipher.getInstance(key.getAlgorithm());
          ecipher.init(Cipher.ENCRYPT_MODE, key);
          //Encode the string into bytes using utf-8
          byte[] utf8 = msg.getBytes("UTF8");
          //Encrypt
          byte[] enc = ecipher.doFinal(utf8);
          //Encode bytes to base64 to get a string
          return new String(Base64.getEncoder().encode(enc));
      } catch (InvalidKeyException e) {
          e.printStackTrace();
      } catch (InvalidKeySpecException e) {
          e.printStackTrace();
      } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
      } catch (NoSuchPaddingException e) {
          e.printStackTrace();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (IllegalBlockSizeException e) {
          e.printStackTrace();
      } catch (BadPaddingException e) {
          e.printStackTrace();
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>I got the output: <strong>QQiu2a4NT9YfDAtmHjbk1A==</strong></p>
  
  <p>Now I try to create the decryption for this:</p>
  
  <pre><code>public static String decrypt(String msg) {
      try {
          KeySpec keySpec = new DESKeySpec(msg.getBytes());
          SecretKey key = 
          SecretKeyFactory.getInstance("DES").generateSecret(keySpec);
          Cipher decipher = Cipher.getInstance(key.getAlgorithm());
          decipher.init(Cipher.DECRYPT_MODE, key);
          // Decode base64 to get bytes
          byte[] dec = Base64.getDecoder().decode(msg.getBytes("UTF-8"));
          //Decrypt
          byte[] utf8 = decipher.doFinal(dec);
          //Decode using utf-8
          return new String(utf8, "UTF8");
      } catch (InvalidKeyException e) {
          e.printStackTrace();
      } catch (InvalidKeySpecException e) {
          e.printStackTrace();
      } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
      } catch (NoSuchPaddingException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (IllegalBlockSizeException e) {
          e.printStackTrace();
      } catch (BadPaddingException e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>However, it doesn't work properly as it returned null :(. Can you please help to check where I'm wrong?</p>