private function XMLSecurityKey::encryptMcrypt in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7
Encrypts the given data (string) using the mcrypt-extension
Parameters
string $data:
Return value
string
1 call to XMLSecurityKey::encryptMcrypt()
- XMLSecurityKey::encryptData in includes/
XMLSecurityKey.php - Encrypts the given data (string) using the regarding php-extension, depending on the library assigned to algorithm in the contructor.
File
- includes/
XMLSecurityKey.php, line 406
Class
Code
private function encryptMcrypt($data) {
$td = mcrypt_module_open($this->cryptParams['cipher'], '', $this->cryptParams['mode'], '');
$this->iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $this->key, $this->iv);
if ($this->cryptParams['mode'] == MCRYPT_MODE_CBC) {
$bs = mcrypt_enc_get_block_size($td);
for ($datalen0 = $datalen = strlen($data); $datalen % $bs != $bs - 1; $datalen++) {
$data .= chr(mt_rand(1, 127));
}
$data .= chr($datalen - $datalen0 + 1);
}
$encrypted_data = $this->iv . mcrypt_generic($td, $data);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $encrypted_data;
}