public static function test_crypto() { //-- $time = microtime(true); //-- //-- $unicode_text = "Unicode String [ " . time() . " ]: @ Smart スマート // Cloud Application Platform クラウドアプリケーションプラットフォーム '" . implode('', array_keys(SmartUnicode::accented_chars())) . " \" <p></p>\n\t? & * ^ \$ @ ! ` ~ % () [] {} | \\ / + - _ : ; , . #'" . microtime() . '#'; //-- //-- $b64enc = base64_encode($unicode_text); $b64dec = base64_decode($b64enc); //-- //-- $bin2hex = strtoupper(bin2hex((string) $unicode_text)); $hex2bin = hex2bin(strtolower(trim((string) $bin2hex))); //-- //-- $hkey = 'TestUnit // This is a test key for Crypto Cipher ...' . time() . $unicode_text; //-- $he_enc = SmartUtils::crypto_encrypt($unicode_text, $hkey); $he_dec = SmartUtils::crypto_decrypt($he_enc, $hkey); //-- if ((string) $he_dec != (string) $unicode_text or sha1($he_dec) != sha1($unicode_text)) { Smart::raise_error('TestUnit FAILED in ' . __FUNCTION__ . '() :: Crypto Cipher test', 'TestUnit: Crypto Cipher test failed ...'); return; } //end if //-- //-- $bf_key = SmartHashCrypto::sha512('TestUnit // This is a test key for Blowfish ...' . time() . $unicode_text); $bf_enc = SmartUtils::crypto_blowfish_encrypt($unicode_text, $bf_key); $bf_dec = SmartUtils::crypto_blowfish_decrypt($bf_enc, $bf_key); if ((string) $bf_dec != (string) $unicode_text or sha1($bf_dec) != sha1($unicode_text)) { Smart::raise_error('TestUnit FAILED in ' . __FUNCTION__ . '() :: Crypto Blowfish test', 'TestUnit: Blowfish test failed ...'); return; } //end if //-- //-- $arch_lzs = SmartArchiverLZS::compressToBase64($unicode_text); $unarch_lzs = SmartArchiverLZS::decompressFromBase64($arch_lzs); if ((string) $unarch_lzs != (string) $unicode_text or sha1($unarch_lzs) != sha1($unicode_text)) { Smart::raise_error('TestUnit FAILED in ' . __FUNCTION__ . '() :: Crypto Arch-LZS test', 'TestUnit: Arch-LZS test failed ...'); return; } //end if //-- //-- $arch_bf_lzs = SmartArchiverLZS::compressToBase64($bf_enc); $unarch_bf_lzs = SmartArchiverLZS::decompressFromBase64($arch_bf_lzs); if ((string) $unarch_bf_lzs != (string) $bf_enc or sha1($unarch_bf_lzs) != sha1($bf_enc)) { Smart::raise_error('TestUnit FAILED in ' . __FUNCTION__ . '() :: Crypto Blowfish-Arch-LZS test', 'TestUnit: Blowfish-Arch-LZS test failed ...'); return; } //end if //-- //-- $time = 'TOTAL TIME was: ' . (microtime(true) - $time); //-- //-- return SmartMarkersTemplating::render_file_template('lib/core/templates/testunit/crypto-test.inc.htm', array('EXE-TIME' => Smart::escape_html($time), 'UNICODE-TEXT' => Smart::escape_html($unicode_text), 'JS-ESCAPED' => $unicode_text, 'HASH-SHA512' => Smart::escape_html(SmartHashCrypto::sha512($unicode_text)), 'HASH-SHA1' => Smart::escape_html(sha1($unicode_text)), 'HASH-MD5' => Smart::escape_html(md5($unicode_text)), 'BASE64-ENCODED' => Smart::escape_html($b64enc), 'BASE64-DECODED' => Smart::escape_html($b64dec), 'BIN2HEX-ENCODED' => Smart::escape_html($bin2hex), 'HEX2BIN-DECODED' => Smart::escape_html($hex2bin), 'LZS-ARCHIVED' => Smart::escape_html($arch_lzs), 'LZS-UNARCHIVED' => Smart::escape_html($unarch_lzs), 'BLOWFISH-ENCRYPTED' => Smart::escape_html($bf_enc), 'BLOWFISH-LZS-ENCRYPTED' => Smart::escape_html($arch_bf_lzs), 'BLOWFISH-DECRYPTED' => Smart::escape_html($bf_dec), 'BLOWFISH-KEY' => Smart::escape_html($bf_key), 'BLOWFISH-OPTIONS' => Smart::escape_html(SmartCipherCrypto::crypto_options('blowfish')), 'HASHCRYPT-ENC' => Smart::escape_html($he_enc), 'HASHCRYPT-DEC' => Smart::escape_html($he_dec), 'HASHCRYPT-OPTIONS' => Smart::escape_html(SmartCipherCrypto::crypto_options('custom')))); //-- }
public static function encode_mime_fileurl($y_msg_file, $y_ctrl_key) { //-- $y_msg_file = (string) trim((string) $y_msg_file); if ((string) $y_msg_file == '') { Smart::log_warning('Mail-Utils / Encode Mime File URL: Empty Message File Path has been provided. This means the URL link will be unavaliable (empty) to assure security protection.'); return ''; } //end if if (!SmartFileSysUtils::check_file_or_dir_name($y_msg_file)) { Smart::log_warning('Mail-Utils / Encode Mime File URL: Invalid Message File Path has been provided. This means the URL link will be unavaliable (empty) to assure security protection. Message File: ' . $y_msg_file); return ''; } //end if //-- $y_ctrl_key = (string) trim((string) $y_ctrl_key); if ((string) $y_ctrl_key == '') { Smart::log_warning('Mail-Utils / Encode Mime File URL: Empty Controller Key has been provided. This means the URL link will be unavaliable (empty) to assure security protection.'); return ''; } //end if if (SMART_FRAMEWORK_ADMIN_AREA === true) { // {{{SYNC-ENCMIMEURL-CTRL-PREFIX}}} $y_ctrl_key = (string) 'AdminMailUtilArea/' . $y_ctrl_key; } else { $y_ctrl_key = (string) 'IndexMailUtilArea/' . $y_ctrl_key; } //end if //-- $crrtime = (int) time(); $access_key = sha1('MimeLink:' . SMART_SOFTWARE_NAMESPACE . '-' . SMART_FRAMEWORK_SECURITY_KEY . '-' . SMART_APP_VISITOR_COOKIE . ':' . $y_msg_file . '>' . $y_ctrl_key); $unique_key = sha1('Time=' . $crrtime . '#' . SMART_SOFTWARE_NAMESPACE . '-' . SMART_FRAMEWORK_SECURITY_KEY . '-' . $access_key . '-' . SmartUtils::unique_auth_client_private_key() . ':' . $y_msg_file . '>' . $y_ctrl_key); $self_robot_key = sha1('Time=' . $crrtime . '#' . SmartAuth::get_login_id() . '*' . SMART_SOFTWARE_NAMESPACE . '-' . SMART_FRAMEWORK_SECURITY_KEY . '-' . SmartUtils::get_selfrobot_useragent_name() . '$' . $access_key . ':' . $y_msg_file . '>' . $y_ctrl_key); //-- {{{SYNC-MIME-ENCRYPT-ARR}}} $safe_link = SmartUtils::crypto_encrypt(trim((string) $crrtime) . "\n" . trim((string) $y_msg_file) . "\n" . trim((string) $access_key) . "\n" . trim((string) $unique_key) . "\n" . trim((string) $self_robot_key) . "\n", 'SmartFramework//MimeLink' . SMART_FRAMEWORK_SECURITY_KEY); //-- return (string) $safe_link; //-- }