在 GNU/Linux 系统上的 /etc/shadow 上使用哪种加密方法?我想为个人目的编写一个使用相同 API 的小程序,但目前我不知道从哪里开始。
提前致谢
在 GNU/Linux 系统上的 /etc/shadow 上使用哪种加密方法?我想为个人目的编写一个使用相同 API 的小程序,但目前我不知道从哪里开始。
提前致谢
使用该crypt(3)
功能。在 glibc 上,使用的方法取决于盐,如果它以:
glibc 中提供了多种加密方法,请参阅 man 3 crypt,Glibc 注释部分: http: //manpages.courier-mta.org/htmlman3/crypt.3.html
验证现有密码时,只需将加密形式作为盐传递;只会使用最初的 $id$salt 部分。创建新密码时,使用您需要的任何内容初始化 id 并将一些随机字符放入 salt 中。
crypt() 的基本示例
#include <stdio.h>
#include <stdlib.h>
#define MAX_STR 256
#define MAX_SALT 12
int main(int argc, char *argv[]) {
char password[MAX_STR];
char salt[MAX_SALT];
printf("salt: ");
scanf("%s", salt);
printf("password: ");
scanf("%s", password);
printf("Encrypt '%s' : '%s'\n", password, crypt(password, salt));
return(EXIT_SUCCESS);
}
编译程序:
$ gcc -lcrypt test.c
我收到
对“crypt”的未定义引用
所以我认为你应该编译
$ gcc test.c -lcrypt