public function testKey() { $keyGeneration1 = new KeyGenerationSHA512RSA4096Bits(); $this->assertNotNull($keyGeneration1->getPublicKey()); $this->assertNotNull($keyGeneration1->getPrivateKey()); $keyGeneration2 = new KeyGenerationSHA512RSA4096Bits('toto'); $this->assertNotNull($keyGeneration2->getPublicKey()); $this->assertNotNull($keyGeneration2->getPrivateKey()); $this->assertNotEquals($keyGeneration1->getPublicKey(), $keyGeneration2->getPublicKey()); $this->assertNotEquals($keyGeneration1->getPrivateKey(), $keyGeneration2->getPrivateKey()); }
public function testSignature() { $key = new KeyGenerationSHA512RSA4096Bits(); $signature = new SignatureSignPrivateKey(); $data1 = 'my data 1'; $signatureData1 = $signature->sign($data1, $key->getPrivateKey()); $this->assertNotEquals($data1, $signatureData1); $data2 = 'my data 2'; $signatureData2 = $signature->sign($data2, $key->getPrivateKey()); $this->assertNotEquals($signatureData1, $signatureData2); $this->assertTrue($signature->verify($data1, $signatureData1, $key->getPublicKey())); $this->assertFalse($signature->verify($data2, $signatureData1, $key->getPublicKey())); }
/** * @param string|null $private_key_path Path to private key file or false for no private key * @param string|null $public_key_path Path to public key file or false for no public key */ public static function createKeypair($private_key_path = false, $public_key_path = false) { $key = new KeyGenerationSHA512RSA4096Bits(); if ($private_key_path) { file_put_contents($private_key_path, $key->getPrivateKey()); } if ($public_key_path) { file_put_contents($public_key_path, $key->getPublicKey()); } }
public function testEncryptionDecryptionRSAWithPassphrase() { $encryption = new EncryptionRSA(); $this->assertInstanceOf('Claudusd\\Cryptography\\Encryption\\EncryptionInterface', $encryption); $message = 'MESSAGE TOP SECRET'; $passphrase = 'my passphrase'; $key1 = new KeyGenerationSHA512RSA4096Bits($passphrase); $messageEncrypted = $encryption->encrypt($message, $key1->getPublicKey()); $this->assertNotEquals($message, $messageEncrypted); $messageDeCrypted = $encryption->decrypt($messageEncrypted, $key1->getPrivateKey(), $passphrase); $this->assertEquals($message, $messageDeCrypted); }
/** */ public static function createKeypair() { $key = new KeyGenerationSHA512RSA4096Bits(); return array($key->getPrivateKey(), $key->getPublicKey()); }