Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to specify the content type for encrypted string?

My script returns an encrypted string but, by default, it's in text/html content type. Should I specify the content type to text/plain instead?

I know it does not harm anything, but what is the right content type for encrypted string?

Updated: string was encrypted using mcrypt_encrypt. There is no concern about security for this data.

like image 810
ln9187 Avatar asked Feb 07 '23 11:02

ln9187


1 Answers

The correct content-type for "a stream of bytes" is application/octet-stream. At its most general, encrypted data is just "a stream of bytes." That said, many other content types may be appropriate depending on the exact format. For instance, if you were working with the OpenPGP format, it defines specific format types that are used, including application/pgp-encrypted and application/pgp-signature as part of a multipart/encrypted message. You are free to invent your own specifications within the MIME framework.

But if you don't have anything better to apply, and don't want to invent anything, the correct fallback is application/octet-stream, which means "here are bytes; please pass them along without interpretation."

It's unclear what you mean by "an encrypted string," but if you mean you've encoded these bytes into UTF-8 or ASCII (using Base64, for example), then text/plain is acceptable if you don't want to express anything more about the data. text/plain does suggest that it's human readable, but you're at least expressing that it's displayable (it doesn't include control characters or other non-printables), so that's not unreasonable. text/html wouldn't make any sense here, since you don't intend it to be interpreted as HTML.

The major difference in practice between application/octet-stream and text/plain is that browsers and browser-like things will tend to download and save application/octet-steam, and will tend to display text/plain. Which behavior you would prefer should drive your choice.

like image 186
Rob Napier Avatar answered May 10 '23 11:05

Rob Napier