PHP Mcrypt, how secure is it really? [closed]

别等时光非礼了梦想. 提交于 2019-11-30 09:30:15

A small guide you could follow to avoid a few pitfalls and apply some recommendations.

  • Do not reuse the same encryption key and initialization vector (IV) for two different messages.

Doing so will risk exposure of the plain-text if an adversary manages to intercept two or more messages during transit using the same key and IV.

  • Don't use ECB mode; OFB and CTR mode are somewhat better, but it's recommended to use CBC or CFB mode.

The main reason to not use ECB is because this mode leaks information about duplicate plain-text blocks which may undermine your encoded stream of data.

OFB and CTR are better, but they suffer from the aforementioned security issue of using the same IV+key combination more than once.

CFB and CBC are the most resilient against IV+key reuse, but separate messages with the same common prefix will leak out the length of said prefix. In addition, CFB leaks out the difference of the first non-identical plain-text blocks.

  • Make sure you have a strong encryption key

    It should not be chosen from printable ASCII (e.g. not "my super strong secret key"); PBKDF2 would be preferred (soon to be supported natively, until then Google it). It should be obvious that this key must be kept safe; if you lose it, bye bye data.

  • Use a good entropy source to generate the initialization vector.

    Mcrypt has an option to use MCRYPT_DEV_RANDOM or MCRYPT_DEV_URANDOM when you call mcrypt_create_iv().

Hope this will help you :)

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