// 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'; list($modulus, $exponent, $key_type) = RSA::keyFromString($key_string_representation);
public function testDecryptNumber() { $encrypted_message = 4051753; $this->RSA->private_key = 6111579; $this->RSA->modulus = 9173503; $this->assertEquals(111111, $this->RSA->decrypt($encrypted_message)); }
/** * get passwd from config * @return mixed|null */ public function getPassword() { $content = file_get_contents($this->getConfigName()); if (!empty($content)) { return $this->encryptInstance->decrypt($content); } return null; }
} $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; } sendResponse(201, '<?xml version="1.0" encoding="UTF-8"?>
<?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;