Encrypting a file using openssl with a password in C
Iam having a text file. I need to encrypt that file with a password. In command line (-k for password and -nosalt 开发者_Go百科-des3) are being used. Is there any sample to achieve the same in C API.
Openssl contains lots of routines for many different crypto systems, including DES. The function you want is probably DES_ncbc_encrypt or one of the other variants, all of which are described on the des(3) man page.
If you are on a Linux System, you can use the crypt function. His prototype is :
#include <unistd.h>
char * crypt(const char *key, const char *salt);
Here is his desription (man 3 crypt) :
The crypt() function performs password encryption, based on the NBS Data Encryption Standard (DES). Additional code has been added to deter key search attempts. The first argument to crypt() is a null-terminated string, typically a user's typed password. The second is in one of two forms: if it begins with an underscore (``_''), an extended format is used in interpreting both the key and the salt value, as outlined below.
精彩评论