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')))); //-- }
/** * Get the auth (safe) stored password from (in-memory) * * @return STRING :: The plain password if was set or empty string */ public static function get_login_password() { //-- if ((string) self::$AuthData['USER_LOGIN_PASS'] == '') { return ''; // empty pass } else { return (string) SmartCipherCrypto::decrypt('hash/sha1', (string) self::$AuthData['KEY'], (string) self::$AuthData['USER_LOGIN_PASS']); } // end if else //-- }
public static function crypto_decrypt($y_data, $y_key = '') { //-- if ((string) $y_key == '') { $key = (string) SMART_FRAMEWORK_SECURITY_KEY; } else { $key = (string) $y_key; } //end if //-- $cipher = 'hash/sha256'; // default if (defined('SMART_FRAMEWORK_SECURITY_CRYPTO')) { $cipher = (string) SMART_FRAMEWORK_SECURITY_CRYPTO; } //end if //-- return (string) SmartCipherCrypto::decrypt((string) $cipher, (string) $key, (string) $y_data); //-- }