Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test file (or resource) for encryption without fully decrypting #427

Closed
crossan007 opened this issue Dec 2, 2018 · 3 comments
Closed

Test file (or resource) for encryption without fully decrypting #427

crossan007 opened this issue Dec 2, 2018 · 3 comments

Comments

@crossan007
Copy link

A core function to test whether a given resource (file, string, etc) has been encrypted by (and therefore is decryptable by) this library (and version?) would be very useful, rather than attempting a decryption and handling the associated exceptions.

The checks present in the beginning of File::decryptResourceInternal() seem like what I desire; but I'd rather handle a boolean response from something like isDecryptableCiphertext() before actually attempting to decrypt a file which may or may not actually have been encrypted.

@defuse
Copy link
Owner

defuse commented Dec 2, 2018

Performance-wise, the only way to (safely) predict if the string will be decryptable by this library is to decrypt it, which is why the way to find out is currently just to try to decrypt it and see if it works. If that's a common pattern, we can wrap it up into a convenient isDecryptableCiphertext() function (option 1).

Another option (option 2) is adding a looksLikeCiphertext() function, which just tells you if the string you pass looks like a ciphertext or not (i.e. does it have the proper headers and a valid length?). You couldn't rely on this function to predict whether or not decryption will succeed (because it could have good headers but a bad authentication tag).

It sounds like you're asking for option 2, right?

@crossan007
Copy link
Author

Yes, number two.

My scenario allows upload by an authenticated user a file which may or may not be encrypted.

Determining if the encryption header is present is all I'm after so I may proceed to prompt the user a password.

@defuse
Copy link
Owner

defuse commented Apr 9, 2021

I won't add it to the library but all ciphertexts produced by this library will start with "\xDE\xF5\x02\x00"

@defuse defuse closed this as completed Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants