Ejemplo n.º 1
0
function decodeAndDecrypt($strIn)
{
    global $strEncryptionPassword;
    if (substr($strIn, 0, 1) == "@") {
        //** HEX decoding then AES decryption, CBC blocking with PKCS5 padding - DEFAULT **
        //** use initialization vector (IV) set from $strEncryptionPassword
        $strIV = $strEncryptionPassword;
        //** remove the first char which is @ to flag this is AES encrypted
        $strIn = substr($strIn, 1);
        //** HEX decoding
        $strIn = pack('H*', $strIn);
        //** perform decryption with PHP's MCRYPT module
        return removePKCS5Padding(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $strEncryptionPassword, $strIn, MCRYPT_MODE_CBC, $strIV));
    } else {
        //** Base 64 decoding plus XOR decryption **
        return simpleXor(base64Decode($strIn), $strEncryptionPassword);
    }
}
Ejemplo n.º 2
0
function decryptAes($strIn, $password)
{
    // HEX decoding then AES decryption, CBC blocking with PKCS5 padding.
    // Use initialization vector (IV) set from $str_encryption_password.
    $strInitVector = $password;
    // Remove the first char which is @ to flag this is AES encrypted and HEX decoding.
    $hex = substr($strIn, 1);
    // Throw exception if string is malformed
    if (!preg_match('/^[0-9a-fA-F]+$/', $hex)) {
        //invelid key
        return false;
    }
    $strIn = pack('H*', $hex);
    // Perform decryption with PHP's MCRYPT module.
    $string = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, $strIn, MCRYPT_MODE_CBC, $strInitVector);
    return removePKCS5Padding($string);
}