0

Is there a library available in java to encrypt a string? Is there any library to encrypt and decrypt an image using AES in Java?

Matthias
  • 3,536
  • 2
  • 30
  • 39
Prashanth
  • 1
  • 4

1 Answers1

1

You can encrypt an image by piping it out to ByteArrayOutputStream, using Cipher.doFinal on the result bytes and writing that to an output source.

Example:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance( ... );
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
output = cipher.doFinal(baos.toByteArray());
David Xu
  • 5,409
  • 3
  • 25
  • 48