I'm trying to use JDK 1.7 JCE (Windows 7 x64) to perform Single DES encryption with CBC on a small block. Each time I run the program below I get different results. The key is the same, the data is the same, what could be wrong?
public class CBCTest {
public static void main(String[] args) throws Exception {
Cipher cc = Cipher.getInstance("DES/CBC/NoPadding");
Key k = new SecretKeySpec(new byte[] {1,1,1,1,1,1,1,1}, "DES");
cc.init(Cipher.ENCRYPT_MODE, k);
byte[] data = new byte[]{1,2,3,4,5,6,7,8};
cc.doFinal(data);
System.out.println("Encrypted: " + Arrays.toString(cc.doFinal(data)));
}
}
Edit:
Changing the Cipher mode to ECB "DES/CBC/NoPadding"
works without a problem.