Ejemplo n.º 1
0
        for ($i=0; $i < $length; $i += 2)
        {
            $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
        }
        return $bindata;
    }

    public static function pkcs5_pad($text, $blocksize)
    {
        $pad = $blocksize - (strlen($text) % $blocksize);
        return $text . str_repeat(chr($pad), $pad);
    }

    public static function pkcs5_unpad($text)
    {
        $pad = ord($text{strlen($text) - 1});
        if ($pad > strlen($text)) return false;
        if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
        return substr($text, 0, -1 * $pad);
    }
}

$aes = new CryptAES();
$aes->set_key('9691bf55bc51f57a711f0068b9c417cd');
$aes->require_pkcs5();
$rt = $aes->encrypt('ssss');

echo "原始的字符串:".$aes->decrypt($rt).'<br />';
echo "加密后的字符串:".$rt;
exit;
?>
Ejemplo n.º 2
0
 *  Script to encrypt or decrypt text using our defined key in config/crypt.php 
 *
 *
 *  Usage: ( from the main vulnDB directory )
 *    php bin/util/kb_to_csv_converter.php /path/to/output/file/to.csv
 *
 *
 *
 **/
if (!is_file($init_file = realpath(dirname(__FILE__)) . "/../../init.php")) {
    echo "Could not find init.php, this file is requied for vulnDB to operate\n";
    exit(1);
}
require $init_file;
if (!isset($argv[1]) || !$argv[2]) {
    Usage();
}
$output_file = $argv[1];
if ($argv[2] == "encrypt") {
    $encrypted_text = CryptAES::encrypt($argv[1]) . "\n";
    echo "\nEncrypted Text: {$encrypted_text}\n    ";
} else {
    if ($argv[2] == "decrypt") {
        $decrypted_text = CryptAES::decrypt($argv[1]) . "\n";
        echo "\nDecrypted Text: {$decrypted_text}\n";
    }
}
function Usage()
{
    echo " \nPlease Supply text to be encrypted.\n\n\nUsage:  php {$_SERVER['SCRIPT_NAME']} <text_to_encrypt> <method>('encrypt' or 'decrypt')\n\n";
}
Ejemplo n.º 3
0
     echo "1.) Yes\n";
     echo "2.) Cancel\n";
     $choice = trim(fgets(STDIN));
     if ($choice == 1) {
         $update = $vulndb->update_account_username($account['account'], $new_username);
         if ($update) {
             echo "Username successfully updated to {$new_username} for {$account['account']}\n";
         }
     } else {
         break;
     }
     break;
 case 4:
     echo "Please enter new password:\n";
     $new_password = trim(fgets(STDIN));
     $new_enc_password = CryptAES::encrypt($new_password);
     echo "\n\n";
     echo "Are you sure you want to update the password for {$account['account']}?\n";
     echo "1.) Yes\n";
     echo "2.) Cancel\n";
     echo "Choice:\n";
     $choice = trim(fgets(STDIN));
     if ($choice == 1) {
         $update_pw = $vulndb->update_account_password($account['account'], $new_enc_password);
         if ($update_pw) {
             echo "Password successfully updated for {$account['account']}\n";
         }
     } else {
         break;
     }
     break;