DES Cipher

Mohammad Hedayati at
Wed Dec 22 16:21:18 UTC 2010

On Wed, Dec 22, 2010 at 7:33 PM, Robert Bonomi <bonomi at> wrote:
>> From owner-freebsd-questions at  Wed Dec 22 08:22:15 2010
>> From: Mohammad Hedayati < at>
>> Date: Wed, 22 Dec 2010 17:50:19 +0330
>> To: freebsd-questions at
>> Subject: DES Cipher
>> Can anyone please show me a sample code for ciphering using DES in FreeBSD?
> I hate to say it, but RTFM applies.
> 'apropos encryption' gives, among other things (and first), a cite to bdes(1).
> 'bdes' is a program that comes with the FreeBSD distribution.
> You have access to the source code of all of the distribution.
> 'Use the Souce, Luke" applies, and will bring the mountain to Mohammad. :)
Thanks Robert, I haven't seen a cite to bdes in the FM of des(3), but
the problem is solved using the source of bdes(1) [thanks to Antone].
The code would be as easy as:

#include <openssl/des.h>

main(int argc, char *argv[])
	DES_key_schedule schedule;
	DES_cblock key;
	strncpy(key, "somekey", 8);
	DES_set_key(&key, &schedule);
	DES_cblock buf;
	strncpy(buf, "sometxt", 8);
	// Encrypting
	DES_ecb_encrypt(&buf, &buf, &schedule, 0);	
	// Decrypting
	DES_ecb_encrypt(&buf, &buf, &schedule, 1);	
	printf("Text Is: %s\n", buf);

More information about the freebsd-questions mailing list