1
$\begingroup$

I'm curious how I could make an app or add a function to an app that will encrypt the data, then a key that will decrypt it. Specifically, I am wanting to be able to add a "button" or setting on the camera app on my phone that will encrypt the image (I imagine encryption via altering the pixels of the image for cool effects, but that may not be logically efficient), then a setting on my gallery that will do the reverse and decrypt it. My main reasoning is to be able to do really cool transformations to images via algorithms (cause that kind of thing is really fun for me), but as a bonus I'll be able to keep my images more secure. I don't know if this is the place to ask, but I'm interested in cryptography (though I'm familiar with the concept, new to the practice), and I thought here may be good. Thank you in advance for any help you can give.

For added details, I'm looking to do this on an iPhone 7+ and galaxy Note 5 so the encrypt/decrypt can work on both, together or separately. This part isn't entirely necessary, but pertains to the specific case I have.

$\endgroup$
  • 1
    $\begingroup$ It's not clear what you're trying to accomplish by encrypting an image. To keep it secure? Against whom? Someone with the phone will have the secret key. To generate "cool effects"? Encrypting an image will just result in random noise, not patterns — it won't even matter what the underlying plaintext image was. $\endgroup$ – Stephen Touset Nov 1 '16 at 23:50
  • $\begingroup$ Interesting. I had thought that by applying an algorithm to the pixels, it would change them in a way that would create interesting patterns. Perhaps that would only occur with simple algorithms that could easily be cracked. Oh well. Looks like I have a lot to learn about cryptology. $\endgroup$ – Lee Fulf Nov 8 '16 at 19:42
  • $\begingroup$ Realistically, this is only the case with broken crypto. For instance, encrypting an image with a block cipher in ECB mode (where each pixel is encrypted independently of the others) shows why such a mode is insecure. In any other mode, you'll just get random noise. $\endgroup$ – Stephen Touset Nov 8 '16 at 19:58
2
$\begingroup$

Generally speaking, it is not up to you to design and implement your own encryption algorithm. The time period where you could do that and maybe get away with it has long since past. Nowadays, we have standardized cipher algorithms such as AES, which are efficient on modern CPUs and believed to be secure against all currently known attacks.

So basically, your question is/should be, "how do I select an algorithm and generate a key for using it?".

My answer is, unless you can cite a specific reason to not use AES, then AES is probably what you should be using. So now that the algorithm has been selected, you need to find an implementation. This is a language dependent issue and you will have to find an appropriate library for the language your program will be in.

Do not just implement AES yourself (for production use; it's fine for fun). There are some "extra" implementation details that can influence the security of the implementation, and these things may be non obvious to those who don't know what to look for.

Key generation is simple: to generate a key, use the key generation function provided by the library that implements AES, or use the OS urandom/CryptGenRandom functions (for UNIX/Windows). A good library should disallow you from using inappropriate key sizes; For AES, 128, 196, and 256 bits are appropriate key lengths.

If you're on multiple platforms, you may want to find a cross platform crypto library to ease the implementation. An easier implementation can lead to less bugs, which can influence security.

Regarding "I imagine encryption via altering the pixels of the image for cool effects, but that may not be logically efficient" - you're going to want to forget about this idea. After successful encryption, any file data will look like noise/scrambled data - if it does not look this way, then you have a problem.

Lastly, unrelated to the crypto: adding a button to the native camera apps on your phone may be more complicated then writing say, a python script to encrypt the contents of the folder where the images are saved. The latter would not require modification of multiple, different, already compiled apps.

Alternative Ciphers

There do exist alternative designs that are both efficient and believed to be secure. If you really do want a different algorithm, this article might be interesting to you. Assuming the alternatives that are suggested are equally secure for practical use, you might implement each and measure which is most efficient for your specific application and platform.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.