Пример #1
0
<?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);
Пример #2
0
<?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;