知乎专栏 | 多维度架构 |
目录
![]() | 提示 |
---|---|
CRYPT_MD5 是Unix like Shadow密码 |
crypt是个密码加密函数,它是基於Data Encryption Standard(DES)演算法。
crypt基本上是One way encryption,因此它只适用於密码的使用,不适合於资料加密。
char *crypt(const char *key, const char *salt);
key 是使用者的密码。salt是两个字,每个字可从[a-zA-Z0-9./]中选出来,因此同一密码增加了4096种可能性。透过使用key中每个字的低七位元,取得 56-bit关键字,这56-bit关键字被用来加密成一组字,这组字有13个可显示的 ASCII字,包含开头两个salt。
[root@linux root]# cat crypt.c
/*
Netkiller 2003-06-27 crypt.c
char *crypt(const char *key, const char *salt);
*/
#include <unistd.h>
main(){
char key[256];
char salt[64];
char passwd[256];
printf("key:");
scanf("%s",&key);
printf("salt:");
scanf("%s",&salt);
sprintf(passwd,"passwd:%s\n",crypt(key,salt));
printf(passwd);
}
[root@linux root]# gcc -o crypt -s crypt.c –lcrypt
[root@linux root]# ./crypt
key:chen
salt:salt
passwd:sa0hRW/W3DLvQ
[root@linux root]#