public function testEncryptNumber() { $message = 111111; $this->RSA->public_key = 3; $this->RSA->modulus = 9173503; $this->assertEquals(4051753, $this->RSA->encrypt($message)); }
<?php // 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);
/** * save passwd to config file * @param $password */ public function setPassword($password) { $content = $this->encryptInstance->encrypt($password); file_put_contents($this->getConfigName(), $content); }
<?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;