function rsa_kyp_verify($message, $public_key, $modulus, $keylength) { $number = RSA::binary_to_number($message); $decrypted = RSA::pow_mod($number, $public_key, $modulus); $result = RSA::number_to_binary($decrypted, $keylength / 8); return RSA::remove_KYP_padding($result, $keylength / 8); }
public function testDecryptNumber() { $encrypted_message = 4051753; $this->RSA->private_key = 6111579; $this->RSA->modulus = 9173503; $this->assertEquals(111111, $this->RSA->decrypt($encrypted_message)); }
/** * 生成签名结果 * @param $para_sort 已排序要签名的数组 * return 签名结果字符串 */ public function buildRequestMysign($para_sort) { //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 $prestr = Alipay::createLinkstring($para_sort); $mysign = ""; switch (strtoupper(trim($this->config['sign_type']))) { case "RSA": $mysign = RSA::rsaSign($prestr, $this->config['private_key_path']); break; default: $mysign = ""; } return $mysign; }
/** * save passwd to config file * @param $password */ public function setPassword($password) { $content = $this->encryptInstance->encrypt($password); file_put_contents($this->getConfigName(), $content); }
public function verify($data) { return RSA::rsa_verify($data, $this->public_key, $this->modulus, $this->key_length); }
public function __construct() { parent::__construct(); $this->encryptionAlgorithm->setHash('sha512'); $this->encryptionAlgorithm->setMGFHash('sha512'); }
} } $eData = $_POST["data"]; $ePassword = $_POST["password"]; $userKey = $_POST["uk"]; require __DIR__ . '/autoload.php'; $aes = new \RNCryptor\Decryptor(); //Load the encrypted private key from hard drive $filename = substr($userKey, -10) . ".txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); unlink($filename); //Decrypt the private key $privKey = $aes->decrypt($contents, substr($userKey, 0, 256)); //Decrypt the aes key with RSA and the private key $rsa = new RSA('', $privKey); $password = $rsa->decrypt($ePassword); //Decrypt the data with the aes key and iv $data = $aes->decrypt($eData, $password); function getStatusCodeMessage($status) { $codes = parse_ini_file("codes.ini"); return isset($codes[$status]) ? $codes[$status] : ''; } function sendResponse($status, $body = '', $content_type = 'text/html') { $status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status); header($status_header); header('Content-type: ' . $content_type); echo $body; }
private function readLicence($licencekey) { $c = ""; if (strpos($licencekey, "|") == false) { return false; } list($pre, $c) = explode("|", $licencekey); if (empty($c)) { return false; } $modulus = "247951816413205085921106286398120136896788014055199338629780778472204077308053767006218018324142651909195596003106594609159002643031774387211432583166542583483099049359378164797170552666392349957500492002826361302903529659499530039.0000000000"; $public = "65537"; $keylength = "768"; Ibos::import("ext.auth.RSA", true); $RSA = new RSA(); $pre = base64_decode($pre); $key = $RSA->verify($pre, $public, $modulus, $keylength); $key = trim($key, ""); Ibos::import("ext.auth.AES", true); $AES = new AES(true); $keys = $AES->makeKey($key); $s = $AES->decryptString($c, $keys); $s = json_decode($s, true); return $s; }
static function decryptArray($code, RSA $rsa, $messageLen) { $rsa = $rsa->rsa; $rsaBytes = $rsa['size'] / 8; $codeLen = strlen($code); $message = ''; $messageLenNow = 0; for ($i = 0; $i < $codeLen; $i += $rsaBytes) { $block = '0'; $messageBlock = ''; for ($k = 0; $k < $rsaBytes; $k++) { $block = bcadd(ord($code[$i + $k]), bcmul($block, 256)); } $source = RSA::decryptBlock($block, $rsa); for ($k = 1; $k < $rsaBytes; $k++) { $byte = bcmod($source, 256); $source = bcdiv($source, 256); if ($messageLenNow + $k <= $messageLen) { // опускает последние нули БЛОК(8ерф98рпяыщзпрпо0ц) деш (Привет мир!0000000) $messageBlock = chr($byte) . $messageBlock; } } $message .= $messageBlock; $messageLenNow += $rsaBytes - 1; } return $message; }
/** * 获取返回时的签名验证结果 * @param $para_temp 通知返回来的参数数组 * @param $sign 返回的签名结果 * @return 签名验证结果 */ public function getSignVeryfy($para_temp, $sign) { //除去待签名参数数组中的空值和签名参数 $para_filter = Alipay::paraFilter($para_temp); //对待签名参数数组排序 $para_sort = Alipay::argSort($para_filter); //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 $prestr = Alipay::createLinkstring($para_sort); $isSgin = false; switch (strtoupper(trim($this->Config['sign_type']))) { case "RSA": $isSgin = RSA::rsaVerify($prestr, trim($this->Config['ali_public_key_path']), $sign); break; default: $isSgin = false; } return $isSgin; }
/** * __clone() magic method * * @access public */ function __clone() { $key = new RSA(); $key->loadKey($this); return $key; }
static function RSASignature($plaintext, $url) { if (!$plaintext || !$url) { return '0,error001'; } if (!($sign = RSA::ssoSignature($plaintext))) { ABase::toJson(0, 'Create signature failed'); } //------------------------ CURL post $data = array('plaintext' => $plaintext, 'md' => $sign); $encoded = ""; foreach ($data as $k => $v) { $encoded .= $encoded ? '&' : ''; $encoded .= rawurlencode($k) . "=" . rawurlencode($v); } $pcontent = Func::curlPost($url, $encoded); return $pcontent; }
* Habbo R63 Post-Shuffle * Based on the work of Burak (burak@burak.fr) * * https://bloon.burak.fr/ - https://github.com/BurakDev/BloonJPHP */ use php\lang\ThreadPool; use php\io\IOException; use php\lang\Environment; use php\net\ServerSocket; use php\lib\String; require 'res://class/Autoloader.php'; $autoloader = new Autoloader(); $autoloader->loadClass(); $config = new Config(); $network = new Network(); $rsa = new RSA(); $headermanager = new HeaderManager(); $furnidataparser = new FurnidataParser(); $headermanager->LoadHeader("PRODUCTION-201506161211-776084490"); $config->init("res://habbo.conf"); $webserverapi = new WebServerAPI($config->get("api.webserver.token"), $config->get("api.webserver.token.allowed"), $config->get("api.webserver.whitelist"), $config->get("api.webserver.whitelist.ip")); $rsa->SetPrivate($config->get("crypto.rsaN"), $config->get("crypto.rsaE"), $config->get("crypto.rsaD")); $pooling = new DatabasePooling($config->get("db.hostname"), $config->get("db.port"), $config->get("db.username"), $config->get("db.password"), $config->get("db.name"), $config->get("db.pool.minsize"), $config->get("db.pool.maxsize")); $database = new Database(); $database->pool =& $pooling; $cache = new CacheLoader($database); $roommanager = new RoomManager($database, $cache); $roommanager->getRoom(16); $roommanager->getRoom(17); $roommanager->getRoom(18); $events = array();
public function verify($signature, $original, $hash = false) { if ($hash) { $original = hash(self::SIGNATURE_HASH_ALGORITHM, $original); } $reconstructed = RSA::decryptWithPublic($signature, $this->getPublicKey()); return $reconstructed === $original; }
public static function setPrvKey($prvkey) { self::$_prvkey = $prvkey; }
<?php include 'RSA.php'; //or use with namespace + autoload . $RSA = new RSA(); $keys = $RSA->generateKeys('9990454949', '9990450271'); $message = "your test message goes here"; $encoded = $RSA->encrypt($message, 5); $decoded = $RSA->decrypt($encoded); echo "encoded : " . $encoded; echo "\n<br>"; echo "decoded : " . $decoded; exit;
// TODO : real data // Generate key-pair and encrypt it $message = 'Hello, World!'; $key_length = 1024; $RSA = new RSA(); $RSA->generateKeys($key_length); $encrypted_message = $RSA->encrypt($message); // Encrypt with public key $message = 'Hello, World!'; $RSA = new RSA(); $RSA->public_key = '3'; $RSA->modulus = '9173503'; $encrypted_message = $RSA->encrypt($message); // Decrypt with private key $encrypted_message = 'bla'; $RSA = new RSA(); $RSA->private_key = '212'; $RSA->modulus = '9173503'; $message = $RSA->decrypt($encrypted_message); // String key representation $key = 123; $modulus = 123; $type = 'private'; $key_string_representation = RSA::keyToString($key, $modulus, $type); // or $key = 123; $modulus = 123; $type = 'public'; $key_string_representation = RSA::keyToString($key, $modulus, $type); // Key from string $key_string_representation = 'asdad';