Java를 사용하여 이미지를 암호화해야합니다. 제대로 이미지를 암호화하지만 이미지를 너무 열거 나 파일이 손상되었다고 알려주므로 파일을 시각화하는 방법을 모르겠습니다. 사진 본문 및 메타 데이터없이 작업하려면 어떻게해야합니까?JAVA : 이미지를 암호화하고 보는 방법
감사합니다.
// Scanner to read the user's password. The Java cryptography
// architecture points out that strong passwords in strings is a
// bad idea, but we'll let it go for this assignment.
Scanner scanner = new Scanner(System.in);
// Arbitrary salt data, used to make guessing attacks against the
// password more difficult to pull off.
byte[] salt = { (byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c,
(byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99 };
{
File inputFile = new File("C:/Users/Julio/Documents/charmander.png");
BufferedImage input = ImageIO.read(inputFile);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeyFactory keyFac = SecretKeyFactory
.getInstance("PBEWithMD5AndDES");
// Get a password from the user.
System.out.print("Password: ");
System.out.flush();
PBEKeySpec pbeKeySpec = new PBEKeySpec(scanner.nextLine()
.toCharArray());
// Set up other parameters to be used by the password-based
// encryption.
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 20);
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
// Make a PBE Cyhper object and initialize it to encrypt using
// the given password.
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
FileOutputStream output = new FileOutputStream(
"C:/Users/Julio/Documents/imgen.png");
CipherOutputStream cos = new CipherOutputStream(output, pbeCipher);
// File outputFile = new File("image.png");
ImageIO.write(input, "PNG", cos);
cos.close();
}
}
출력 비트를 새로운'.png' 파일에 직접 쓰고 있습니다. 아마도 올바른 메타 데이터를 작성해야하며 그런 다음 암호화 된 데이터를 작성해야합니까? '.png'에는 [여기] (http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html)에서 볼 수있는 표준이 있습니다. – christopher
각 픽셀의 색상 코드를 단순히 바이트로 지정하는 원시 이미지의 경우이 방법을 사용하는 것이 더 쉽습니다 (예 : [.bmp 형식] (http://en.wikipedia.org/wiki/BMP_file_format). –