c - 为什么 crypt 函数在这里不起作用?

标签 c linux crypt

我链接了 -lcrypt ,问题是无论我的命令行参数如何,我都得到了相同的加密。如果我改变盐,加密似乎只会改变。我的代码中的什么会导致此缺陷?

#define _XOPEN_SOURCE       
#include <unistd.h>
#include <math.h>
#include <stdio.h>
#include <string.h>


int main(int argc, char *enc[])
{
if (argc != 2)
{  
    printf("Improper command-line arguments\n");
    return 1;
}
char *salt = "ZA";

printf("%s \n", crypt(*enc, salt));

}

最佳答案

crypt(*enc, salt) 中,您正在加密您的第一个 参数,它是程序的名称,而不是第一个实际参数。请尝试使用 crypt(enc[1], salt)

关于c - 为什么 crypt 函数在这里不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21741336/

相关文章:

php - 将 PHP crypt() 结果存储在数据库中是否安全?

c - 索引转换 : row-major to cartesian coordinates (e. g.,像素)

linux - 我被黑了吗?未知进程 dsfref、gfhddsfew、dsfref 等在 centos 6.5 中自动启动

c - 查找输入中最长的单词时出现段错误

c - LD_PRELOAD、bash 和 printf

c - Linux/Unix 控制台图形/控制

javascript - node.js rsa 加密/解密

c - '错误: scheduling while atomic' with crypto_alloc_hash

c++ - C/C++ 编译器警告 : do you clean up all your code to remove them or leave them in?

c/unix : abort process that runs for too long