Source code such as the following:
#include <stdio.h>#include <unistd.h>intMainintARGC, Char*ARGV[]){if(ARGC! =3){printf("%s <salt> <crypt>\n", argv[0]);return-1; } Char*passwd=Crypt(argv[1],argv[2]);printf("passwd: %s\ n", passwd);return 0;}
Summarize:
char *crypt (const char *key , const char *salt); Crypt is a password cryptographic function, which is based on the Data Encryption Standard (DES) algorithm. Crypt is only applicable to the use of password and is not suitable for data encryption.
crypt()将參数key所指的字符串加以加密。key字符串长度仅取前8个字符,超过此长度的字符没有意义。參数salt为两个字符组成的字符串,由a-z、A-Z、0-9。“.”和“/”所组成,用来决定使用4096 (a-z、A-Z、0-9。“.”和“/”共64个字符。64的平方为4096)种不同内建表格的哪一个。函数运行成功后会返回指向编码过的字符串指针,參数key 所指的字符串不会有所更动。编码过的字符串长度为13 个字符。前两个字符为參数salt代表的字符串。返回值: 返回一个指向以NULL结尾的password字符串。注意编译时要在末尾加入 -lcrypt 选项。
Linux password Encryption Program (can be used to replace the user in the shadow file password)