crypt() — String encoding function

Standards

Standards / Extensions C or C++ Dependencies
XPG4
XPG4.2
Single UNIX Specification, Version 3
both  

Format

#define _XOPEN_SOURCE
#include <unistd.h>

char *crypt(const char *key, const char *salt);

General description

The crypt() function encodes the string pointed to by the key argument. It perturbs the Data Encryption Standard (DES) encryption algorithm with the first two characters in the string pointed to by the salt argument to perform this encoding. The first two salt characters must be chosen from the set:
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 . /

This function can be called from any thread.

Returned value

If successful, crypt() returns a pointer to a thread specific encoded string. The first two characters of the returned value are those of the salt argument.
Notes:
  1. The return value of crypt() points to a thread-specific buffer which is overwritten each time crypt() is called from the same thread.
  2. The values returned by crypt() are not portable to other X/Open-conforming systems.

If unsuccessful, crypt() returns a NULL pointer and sets errno to indicate the error.

Special behavior for z/OS® UNIX Services: The crypt() function will fail if:
Error Code
Description
EINVAL
First two characters of salt argument are not from the salt set.
ENOMEM
Storage for crypt() output buffer is not available for thread from which crypt() has been invoked.

Related information