Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022



encrypt - encoding function


#include <crypt.h>

void encrypt(char block[64], int edflag);

Standard conforming

#include <unistd.h>

void encrypt(char block[64], int edflag);


The encrypt() function provides (rather primitive) access to the hashing algorithm employed by the crypt_unix(7) algorithm. The key generated by setkey(3C) is used to encrypt the string block with encrypt().

The block argument to encrypt() is an array of length 64 bytes containing only the bytes with numerical value of 0 and 1. The array is modified in place to a similar array using the key set by setkey(3C). If edflag is 0, the argument is encoded. If edflag is 1, the argument may be decoded (see the USAGE section below); if the argument is not decoded, errno will be set to ENOSYS.

Return Values

The encrypt() function returns no value.


The encrypt() function will fail if:


The functionality is not supported on this implementation.


The DES standard was officially withdrawn by NIST in 2005, and the algorithm is no longer recommended for modern usage. Oracle Solaris may remove the remaining support for single-DES in a future update. Please upgrade your applications to use more modern ciphers and hashes and longer key lengths, such as those provided by openssl(7).

Because encrypt() does not return a value, applications wishing to check for errors should set errno to 0, call encrypt(), then test errno and, if it is non-zero, assume an error has occurred.


See attributes(7) for descriptions of the following attributes:

Interface Stability
Obsolete Committed
See below.

The encrypt() function is defined in the XPG1 through XPG7 standards, and POSIX.1-2001 through POSIX.1-2017 standards, but has been declared Obsolete and may be removed from future POSIX and XPG standards. See standards(7) for more information on these standards.

See Also

crypt(3C), setkey(3C), attributes(7), crypt_unix(7)