I have a ciphertext and a 256-bit key to decrypt it, using AES. There is no salt or iv. I am using Java. I have implemented many of the solutions online, but they all use salts and input vectors. The following builds fine, but fails at runtime: "Salt not found." What salt?
public class AESFileDecryption {
public static void main(String[] args) throws Exception {
String password = "80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01";
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec keySpec = new PBEKeySpec(password.toCharArray());
SecretKey tmp = factory.generateSecret(keySpec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
// file decryption
Cipher cipher = Cipher.getInstance();
cipher.init(Cipher.DECRYPT_MODE,secret);
FileInputStream fis = new FileInputStream("encryptedfile.des");
FileOutputStream fos = new FileOutputStream("plainfile_decrypted.txt");
byte[] in = new byte[64];
int read;
while ((read = fis.read(in)) != -1) {
byte[] output = cipher.update(in, 0, read);
if (output != null)
fos.write(output);
}
byte[] output = cipher.doFinal();
if (output != null)
fos.write(output);
fis.close();
fos.flush();
fos.close();
System.out.println("File Decrypted");
}
}
You can decrypt the ciphertext in exercise 3.8 by using the simple ECB mode of AES, which does not use an IV. Since you have the key, there is no need for salt (there is no key derivation). Use AES 256 ECB mode in Java, and pass the key as shown. These openssl commands at the command line show that this will work:
You have to convert the hex shown in the book to a string of bytes, for example:
You have to use the key as a string of 32 bytes, for example, the openssl command line converts hex to bytes for you with the -K argument:
And you can convert the resulting binary plaintext back to a hex string for viewing, as in
For example:
The result is:
If you let the Java class strip the padding, the result will be 15 bytes of plaintext as:
This should be enough for you to jump in with the Java classes and reproduce the same result. I just wanted to show you that this will work with AES 256 ECB, without any IV or salt involved.