コード例 #1
0
 public static function verify($y_form_name, $y_mode, $y_clear = true)
 {
     //--
     $y_form_name = trim((string) $y_form_name);
     //--
     $ok = 1;
     // default, if not active
     //--
     if (self::validate_form_name($y_form_name) !== 1) {
         return 0;
         // invalid form name
     }
     //end if
     //--
     $cookie_name = self::cookiename($y_form_name);
     //--
     if ((string) $y_mode == 'session') {
         //--
         $cookie_value = (string) SmartSession::get((string) $cookie_name);
         $run_mode = 'session';
         //--
     } else {
         //--
         $cookie_value = (string) $_COOKIE[(string) $cookie_name];
         $run_mode = 'cookie';
         //--
     }
     //end if else
     //--
     $var_name = self::jscookiename($y_form_name);
     $var_value = trim((string) $_COOKIE[(string) $var_name]);
     //--
     if ((string) $var_value != '') {
         $arr_value = explode('!', base64_decode(SmartUtils::crypto_blowfish_decrypt(SmartArchiverLZS::decompressFromBase64((string) $var_value), sha1($y_form_name . SMART_FRAMEWORK_SECURITY_KEY))));
         // explode by '!'
     }
     //end if
     //--
     $ok = 0;
     // error check by default
     //--
     if (@strlen($var_value) > 0 and (string) $cookie_value == (string) self::checksum(trim($arr_value[1]))) {
         //--
         $ok = 1;
         //--
         if ($y_clear == true) {
             // clear is optional (there are situations when after veryfying captcha, even if OK, other code must be run and if that code returns error, still captcha must be active, not cleared (so clearing it manually is a solution ...)
             self::clear($y_form_name, $y_mode);
         }
         //end if
         //--
     }
     //end if
     //--
     return $ok;
     //--
 }
コード例 #2
0
 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'))));
     //--
 }