简体   繁体   中英

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 -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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM