Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mcrypt_generic(3) [php man page]

MCRYPT_GENERIC(3)							 1							 MCRYPT_GENERIC(3)

mcrypt_generic - This function encrypts data

SYNOPSIS
string mcrypt_generic (resource $td, string $data) DESCRIPTION
This function encrypts data. The data is padded with " " to make sure the length of the data is n * blocksize. This function returns the encrypted data. Note that the length of the returned string can in fact be longer than the input, due to the padding of the data. If you want to store the encrypted data in a database make sure to store the entire string as returned by mcrypt_generic, or the string will not entirely decrypt properly. If your original string is 10 characters long and the block size is 8 (use mcrypt_enc_get_block_size(3) to determine the blocksize), you would need at least 16 characters in your database field. Note the string returned by mdecrypt_generic(3) will be 16 characters as well...use rtrim($str, "") to remove the padding. If you are for example storing the data in a MySQL database remember that varchar fields automatically have trailing spaces removed during insertion. As encrypted data can end in a space (ASCII 32), the data will be damaged by this removal. Store data in a tinyblob/tinytext (or larger) field instead. PARAMETERS
o $td - The encryption descriptor. The encryption handle should always be initialized with mcrypt_generic_init(3) with a key and an IV before calling this function. Where the encryption is done, you should free the encryption buffers by calling mcrypt_generic_deinit(3). See mcrypt_module_open(3) for an example. o $data - The data to encrypt. RETURN VALUES
Returns the encrypted data. SEE ALSO
mdecrypt_generic(3), mcrypt_generic_init(3), mcrypt_generic_deinit(3). PHP Documentation Group MCRYPT_GENERIC(3)

Check Out this Related Man Page

ENCRYPT(2)							System Calls Manual							ENCRYPT(2)

NAME
encrypt, decrypt, netcrypt - DES encryption SYNOPSIS
#include <u.h> #include <libc.h> int encrypt(void *key, void *data, int len) int decrypt(void *key, void *data, int len) int netcrypt(void *key, void *data) DESCRIPTION
Encrypt and decrypt perform DES encryption and decryption. Key is an array of DESKEYLEN (defined as 7 in <auth.h>) bytes containing the encryption key. Data is an array of len bytes; it must be at least 8 bytes long. The bytes are encrypted or decrypted in place. The DES algorithm encrypts an individual 8 byte block of data. Encrypt uses the following method to encrypt data longer than 8 bytes. The first 8 bytes are encrypted as usual. The last byte of the encrypted result is prefixed to the next 7 unencrypted bytes to make the next 8 bytes to encrypt. This is repeated until fewer than 7 bytes remain unencrypted. Any remaining unencrypted bytes are encrypted with enough of the preceding encrypted bytes to make a full 8 byte block. Decrypt uses the inverse algorithm. Netcrypt performs the same encryption as a SecureNet Key. Data points to an ASCII string of decimal digits with numeric value between 0 and 10000. These digits are copied into an 8 byte buffer with trailing binary zero fill and encrypted as one DES block. The first four bytes are each formatted as two digit ASCII hexadecimal numbers, and the string is copied into data. SOURCE
/sys/src/libc/port DIAGNOSTICS
These routines return 1 if the data was encrypted, and 0 if the encryption fails. Encrypt and decrypt fail if the data passed is less than 8 bytes long. Netcrypt can fail if it is passed invalid data. SEE ALSO
securenet(8) BUGS
The source is not included in public distributions. The implementation is broken in a way that makes it unsuitable for anything but authentication. ENCRYPT(2)
Man Page