Is the file Encrypted with AES? [closed]

我只是一个虾纸丫 提交于 2019-12-02 19:24:32

问题


Is there a way to tell if a file has been encrypted already if I know the Algorithm was AES?

I would have been the one to encrypt it, so information to decrypt or encrypt is not a problem. However, if you try to decrypt a file that has not been encrypted you'll lose all the data. If you encrypt it twice, you get a double encryption. You can reverse a double encryption but you need to know that it is encrypted twice.

Is there a way to determine programatically?

I'm doing this in Java.


回答1:


there is no way to tell if anything has been encrypted with AES, it doesnt leave a signature, thats part of the point. although you can infer that its probably been encrypted with AES or some other 128bit block cipher by testing if the length of the data in bytes is a multiple of 16, suggesting a 128bit block cipher with padding on the last block




回答2:


It depends on the unencrypted file format. If your unencrypted file has a specific file header, you can search for that header. If you find it, the file is unencrypted. If you don't find it the file could be encrypted.

If your unencrypted file does not have a specific file header ... then tough luck.




回答3:


If you're open to using an external program, you can use openssl to attempt to decrypt the data. As long as you provide a non-blank password on unencrypted data it will return with a "bad magic number" error. Not sure yet exactly how openssl is generating that message (if I could you could do that in your code), but it's a start.

$ openssl enc -d -aes-256-cbc -in /Applications/Wireshark.app/Contents/MacOS/Wireshark
enter aes-256-cbc decryption password:
bad magic number

Another method would be to check the first 8 characters of the file are "Salted__" and the following 8 characters are the salt (provided the encryption was salted which the openssl binary does by default but can be disabled).

0000000: 5361 6c74 6564 5f5f 70d6 3655 ae12 58de Salted__p.6U..X.



来源:https://stackoverflow.com/questions/15014053/is-the-file-encrypted-with-aes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!