How to get Perl crypt to encrypt more than 8 characters?

时光毁灭记忆、已成空白 提交于 2019-12-02 02:04:32

问题


Only the first 8 characters is encrypted when the Perl crypt function is used. Is there a way to get it to use more characters?

As an example:

$crypted_password = crypt ("PassWord", "SALT");

and

$crypted_password = crypt ("PassWord123", "SALT");

returns exactly the same result. $crypted_password has exactly the same value.

Would love to use crypt because it is a quick and easy solution to some none reversible encryption but this limit does not make it useful for anything serious.


回答1:


To quote from the documentation:

Traditionally the result is a string of 13 bytes: two first bytes of the salt, followed by 11 bytes from the set [./0-9A-Za-z], and only the first eight bytes of PLAINTEXT mattered. But alternative hashing schemes (like MD5), higher level security schemes (like C2), and implementations on non-Unix platforms may produce different strings.

So the exact return value of crypt is system dependent, but it often uses an algorithm that only looks at the first 8 byte of the password. These two things combined make it a poor choice for portable password encryption. If you're using a system with a stronger encryption routine and don't try to check those passwords on incompatible systems, you're fine. But it sounds like you're using an OS with the old crappy DES routine.

So a better option is to use a module off of CPAN that does the encryption in a predictable, more secure way.

Some searching gives a few promising looking options (That I haven't used and can't recommend one over another; I just looked for promising keywords on metacpan):

  • Crypt::SaltedHash
  • Authen::Passphrase::SaltedDigest
  • Crypt::Bcrypt::Easy
  • Crypt::Password::Util


来源:https://stackoverflow.com/questions/55758301/how-to-get-perl-crypt-to-encrypt-more-than-8-characters

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