When initializing a cipher with a generated key in encrypt mode there are some parameters which are created underneath the covers which need to be given to the decrypter (related to the mode and padding which you specified in getting the instance of the cipher).
1) Using c = Cipher.getInstance("DES/CBC/PKCS5Padding"); indicates that you wish to use CBC mode so you will need an initialisation vector (IV). For DES this will be 8 bytes used as byte ivBytes = your IV bytes IvParameterSpec iv = new IvParameterSpec(ivBytes); cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key, iv); You will need to supply the same IV when you decrypt.
2) Using String y = new String(c.doFinal(x.getBytes())); has two problems -
a) x.getBytes() uses the default platform encoding to turn characters into bytes so you 'may' get a different result for different platforms. It is normally better to specify the encoding i.e. x.getBytes("utf-8") then the same bytes will be generated for ALL platforms. b) String y = new String(c.doFinal(...)) tries to turn the arbitrary bytes generated by the encryption process into a String using the default platform encoding. As well as the problems outlined in a), this has the additional problem that not all bytes and byte sequences can represent a valid character so the transformation is frequently not reversible. If you MUST have a String result from the encryption then use Base64 or Hex to armor the bytes.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.