Encrypting with DES and password
I'm using the code I've found here to encrypt using DES. I'm sending this value to 3rd party servce, but doesn't seem to work.
Question in code given code, salt and iteration are used as parameters to create initialize the cipher with the parameter spec:
// Prepare the parameter to the ciphers AlgorithmParameterSpec paramSpec = new PBEParameterSpec( salt, iterationCount ); // Create the ciphers ecipher.init(Cipher.ENCRYPT_MODE, key , paramSpec); dcipher.init(Cipher.DECRYPT_MODE, key , paramSpec);
If I change the iteration count, I have different results.
How can I know what is being used in the other side of the wire? The only thing I know from this third party service, is, the algorithm to use is DES and of course the secret password.
What am I missing?
"DES" itself is just a single iteration. Its successor, "Triple DES" encrypts each data block three times performs three iterations of the algorithm. If you are expected to perform encryption using just "DES", one iteration should be correct.
In general, it is considered bad practice to write your own cryptographic functions for anything other than toy implementations. Writing secure, correct libraries for cryptography can sometimes be tricky. Consider using the Java Cryptography Architecture, part of the Java Platform SE 6.