1Z0-829 Java I/O API and Securing Applications Practice Question
Exhibit
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
try (CipherOutputStream cos = new CipherOutputStream(new FileOutputStream("data.enc"), cipher)) {
Files.copy(Path.of("data.txt"), cos);
}Refer to the exhibit. What is the purpose of this code?
⚠ Common exam trap
Oracle often tests the distinction between encryption and compression, and the direction of the cipher mode (ENCRYPT vs DECRYPT) relative to the input/output file names, leading candidates to confuse the source and destination or the operation type.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Encrypt data.txt and write to data.enc
The code uses a CipherOutputStream with a cipher initialized in ENCRYPT_MODE, reading from data.txt and writing to data.enc, thus encrypting the plaintext file and producing an encrypted output file. This is the standard pattern for file encryption in Java using the JCA (Java Cryptography Architecture).
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Compress data.txt and write to data.enc
Why it's wrong here
CipherOutputStream performs encryption, not compression.
- ✓
Encrypt data.txt and write to data.enc
Why this is correct
The cipher is in encrypt mode, and data from data.txt is written to data.enc via CipherOutputStream.
- ✗
Encrypt data.enc and write to data.txt
Why it's wrong here
The source is data.txt and target is data.enc, not the other way.
- ✗
Decrypt data.txt and write to data.enc
Why it's wrong here
Cipher is in ENCRYPT_MODE, so it encrypts, not decrypts.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.