-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
opengeek edited this page Nov 11, 2010
·
1 revision
A basic usage example of the modCipher service class:
/* get the modCipher service class as $modx->cipher */
$modx->getService('cipher', 'modx.cipher.modCipher', MODX_CORE_PATH . 'components/modcipher/model/');
/* get descriptor handle for the tripledes algorithm in OFB mode */
$modx->cipher->open(MCRYPT_TRIPLEDES, MCRYPT_MODE_OFB);
/* generate a random initialization vector (for Windows before 5.3, use MCRYPT_RANDOM) */
$modx->cipher->config['iv'] = $modx->cipher->generateIV(MCRYPT_DEV_URANDOM);
/* generate a super-secret key for use in the ciphering */
$modx->cipher->config['key'] = $modx->cipher->generateKey('food and beer!');
/* encrypt a string */
$encrypted = $modx->cipher->encrypt("Food or beer? That is the question!");
/* decrypt the string you encrypted */
$decrypted = $modx->cipher->decrypt($encrypted);