I was wondering if there is a smart way for a user to only encrypt a subset of a plaintext.

I'll try to be more specific. Let's suppose the user U wants to use a special cipher such that given a plaintext P and some additional information, it only encrypts the subset requested by the user, the rest of the plaintext is not modified.

Does it exist such a cipher? If so, where can I find it and how does it work? If not, how would you do design such a cipher?


EDIT: I've read about selective encryption but it looks like it's mainly meant for images and video streams

  • $\begingroup$ What do you mean with "subset of P"? You can use any cipher. What data you put through and what not is completely your choice and of no relevance for the cipher. $\endgroup$ – marstato Aug 5 '14 at 14:04
  • $\begingroup$ In practice, you probably want an AEAD scheme. It is almost always the case that your encrypted data should also be authenticated, and with AEAD your non-encrypted data will also be authenticated. $\endgroup$ – otus Aug 5 '14 at 14:07
  • $\begingroup$ @marstato "subset of P" means a subset of the bytes of P. What I'm wondering whether exists or not is a cipher that given a plaintext + some data it only encrypts the bytes the user asked to encrypt. $\endgroup$ – pAkY88 Aug 5 '14 at 14:12
  • $\begingroup$ @otus thank you for the advice! I'll have a look at it. Why don't you write an answer? I might accept it. $\endgroup$ – pAkY88 Aug 5 '14 at 14:13
  • $\begingroup$ Is there one continuous subset or many disjointed subsets? Do you require that the output (of plaintext and ciphertext) be the same length as the input plaintext? Do you want the ciphertext to be in-line with the plaintext? $\endgroup$ – mikeazo Aug 5 '14 at 15:49

You can get what you want programmatically. No special ciphers or modes needed.

You say there is a single, continuous subset that needs to be encrypted. Thus, you could have a function where the programmer specifies the start of the portion of the plaintext that needs to be encrypted and the number of bytes to encrypt. The function could pull that part out, encrypt it (using a good block cipher and mode) into a buffer. Then write out the part preceding it, the ciphtertext, then the part following the portion that needs to be encrypted.

If you require integrity checks too, a simple HMAC of the plain-part-one + ciphertext + plain-part-two using a different key would do.


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.