You are here

function _ldap_servers_decrypt in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/ldap_servers.encryption.inc \_ldap_servers_decrypt()
  2. 7 ldap_servers/ldap_servers.encryption.inc \_ldap_servers_decrypt()

Encrypt Decrypt Method

Parameters

string $cipher_txt: ciphered text.

Return value

string clear text

http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypt...

1 call to _ldap_servers_decrypt()
ldap_servers_decrypt in ldap_servers/ldap_servers.module

File

ldap_servers/ldap_servers.encryption.inc, line 128
Provides functions for encryption/decryption. http://stackoverflow.com/questions/2448256/php-mcrypt-encrypting-decrypt...

Code

function _ldap_servers_decrypt($cipher_txt, $enc_type = NULL) {
  $key = config('ldap_servers.settings')
    ->get('encrypt_key');
  if (!$enc_type) {
    $enc_type = config('ldap_servers.settings')
      ->get('encryption');
  }
  if ($enc_type == LDAP_SERVERS_ENC_TYPE_CLEARTEXT) {
    return $cipher_txt;
  }
  $cipher_txt = base64_decode($cipher_txt);
  switch ($enc_type) {
    case LDAP_SERVERS_ENC_TYPE_BLOWFISH:

      // Blowfish
      $clear_txt = "";
      $td = mcrypt_module_open('blowfish', '', LDAP_SERVERS_CYPHER_MODE, '');
      $ivsize = mcrypt_enc_get_iv_size($td);
      $iv = substr($cipher_txt, 0, $ivsize);
      $cipher_txt = substr($cipher_txt, $ivsize);
      if ($iv) {
        mcrypt_generic_init($td, $key, $iv);
        $clear_txt = mdecrypt_generic($td, $cipher_txt);
      }
      break;
    default:

      // Cleartext
      $clear_txt = $cipher_txt;
  }
  return $clear_txt;
}