Source:
<code>public static void getObject_test6() throws Exception { System.out.println( "Test: client side encryption (AES 256 bit): getObject(String bucketName, String objectName, " + "EncryptionMaterials encryptionMaterials)."); String fileName = createFile(13 * MB); InputStream is = Files.newInputStream(Paths.get(fileName)); KeyGenerator symKeyGenerator = KeyGenerator.getInstance("AES"); symKeyGenerator.init(128); SecretKey symKey = symKeyGenerator.generateKey(); try { client.putObject(bucketName, fileName, is, 20 * 1024 * 1024, null, symKey); } catch (InsufficientDataException e) { ignore(); } is.close(); String plainFileName = createFile(0); InputStream ois = client.getObject(bucketName, fileName); OutputStream os = Files.newOutputStream(Paths.get(plainFileName)); int numRead = 0; byte[] buf = new byte[8192]; while ((numRead = ois.read(buf)) >= 0) { os.write(buf, 0, numRead); } os.close(); ois.close(); File file1 = new File(fileName); File file2 = new File(plainFileName); if (FileUtils.contentEquals(file1, file2)) { throw new MinioException("Files should not be equal"); } String decFileName = createFile(0); ois = client.getObject(bucketName, fileName, symKey); os = Files.newOutputStream(Paths.get(decFileName)); numRead = 0; buf = new byte[8192]; while ((numRead = ois.read(buf)) >= 0) { os.write(buf, 0, numRead); } os.close(); ois.close(); file1 = new File(fileName); file2 = new File(decFileName); if (!FileUtils.contentEquals(file1, file2)) { throw new MinioException("Files should be equal"); } Files.delete(Paths.get(fileName)); Files.delete(Paths.get(plainFileName)); Files.delete(Paths.get(decFileName)); client.removeObject(bucketName, fileName); <START> } <END></code><technical_language>do need test this</technical_language>

Target:
public static void getObject_test6() throws Exception { System.out.println( "Test: encryption (AES): getObject(String bucketName, String objectName, " + "SecretKey key)."); String fileName = createFile(13 * MB); InputStream is = Files.newInputStream(Paths.get(fileName)); KeyGenerator symKeyGenerator = KeyGenerator.getInstance("AES"); symKeyGenerator.init(128); SecretKey symKey = symKeyGenerator.generateKey(); try { client.putObject(bucketName, fileName, is, 13 * 1024 * 1024, null, symKey); } catch (InsufficientDataException e) { throw new MinioException("Insufficient data received"); } is.close(); InputStream ois = client.getObject(bucketName, fileName); String plainFileName = getRandomName(); OutputStream os = Files.newOutputStream(Paths.get(plainFileName)); int numRead = 0; byte[] buf = new byte[8192]; while ((numRead = ois.read(buf)) >= 0) { os.write(buf, 0, numRead); } os.close(); ois.close(); if (Arrays.equals(Files.readAllBytes(Paths.get(plainFileName)), Files.readAllBytes(Paths.get(fileName)))) { throw new MinioException("Files should not be equal"); } ois = client.getObject(bucketName, fileName, symKey); String decFileName = getRandomName(); os = Files.newOutputStream(Paths.get(decFileName)); numRead = 0; buf = new byte[8192]; while ((numRead = ois.read(buf)) >= 0) { os.write(buf, 0, numRead); } os.close(); ois.close(); if (!Arrays.equals(Files.readAllBytes(Paths.get(decFileName)), Files.readAllBytes(Paths.get(fileName)))) { throw new MinioException("Files should be equal"); } Files.delete(Paths.get(fileName)); Files.delete(Paths.get(plainFileName)); Files.delete(Paths.get(decFileName)); client.removeObject(bucketName, fileName); }