- 論壇徽章:
- 0
|
php里面查到是這樣的:
CRYPT_STD_DES - Standard DES-based encryption with a two character salt
CRYPT_EXT_DES - Extended DES-based encryption with a nine character salt
CRYPT_MD5 - MD5 encryption with a twelve character salt starting with
$1$
CRYPT_BLOWFISH - Blowfish encryption with a sixteen character salt
starting with $2$ or $2a$
并且有這樣的示例:
if (CRYPT_STD_DES == 1) {
echo 'Standard DES: ' . crypt('rasmuslerdorf', 'rl') . "\n";
}
if (CRYPT_EXT_DES == 1) {
echo 'Extended DES: ' . crypt('rasmuslerdorf', '_J9..rasm') . "\n";
}
if (CRYPT_MD5 == 1) {
echo 'MD5: ' . crypt('rasmuslerdorf', '$1$rasmusle$') . "\n";
}
if (CRYPT_BLOWFISH == 1) {
echo 'Blowfish: ' . crypt('rasmuslerdorf', '$2a$07$rasmuslerd...........$') . "\n";
}
?>
在linux和windows下,都只支持標(biāo)準(zhǔn)DES和md5加密這2種,不知其他2個(gè)怎么折騰出來;
python的crypt模塊也只是對(duì)標(biāo)準(zhǔn)和md5說了下,看來也是同樣情況;
標(biāo)準(zhǔn)DES加密:
是從64個(gè)字符(大小寫A-Z,0-9,還有/ .)挑2個(gè)作為salt;
擴(kuò)展DES: 挑9個(gè);
標(biāo)準(zhǔn)MD5: 是挑8個(gè),然后用$1$SALT$, 這樣12個(gè)字符作為salt;
BLOWFISH: 沒明白,說是16個(gè)字符,可數(shù)來數(shù)去都不止;
姑且照葫蘆畫瓢,把BLOWFISH當(dāng)成16個(gè)字符:
===============================================================
import random,crypt,getpass
salt = ''
print """
crypt method choose:
1) standard DES
#2) extended DES
3) MD5
#4) BLOWFISH
"""
choosenum = int(raw_input())
if choosenum == 1: totalnum = 2
#elif choosenum == 2: totalnum = 9
elif choosenum == 3: totalnum = 8
#elif choosenum == 4: totalnum = 12
else:
print "choose error num"
sys.exit(0)
for i in range(0,totalnum):
salt = salt + random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./0123456789')
#print "salt is:", salt
newpass = getpass.getpass("pls input your password:")
if choosenum == 3:
print crypt.crypt(newpass,"$1$" + salt + "$")
elif choosenum == 1 or choosenum == 2 :
print crypt.crypt(newpass,salt)
#elif choosenum == 4:
# print crypt.crypt(newpass,"$2$" + salt + "$")
得到的加密字符,取代shadow文件中的密碼部分;
本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u1/57278/showart_1163128.html |
|