예제 #1
0
 public function testDerivation()
 {
     $input = 'presumablyADiffieHellmanResult';
     $derivation = AES::deriveKey($input);
     $arbitraryText = 'correcthorsebatterystaple';
     $derivedKey = AES::deriveKey($arbitraryText);
     // var_dump($derivedKey);
     $this->assertEquals('CfSmnHxb6DEdPg7+/+LmPrbHIjFb6e0Z5fzv+psTKSM=', $derivation, 'derivation works');
 }
예제 #2
0
 public function calculateSymmetricKey($publicKey = null, $deriveKey = true)
 {
     if ($publicKey == null) {
         $publicKey = $this->getPublicKey();
     }
     $diffieHellman = ECC::diffieHellman($publicKey, $this->getPrivateKey());
     if ($deriveKey) {
         return AES::deriveKey($diffieHellman);
     }
     return $diffieHellman;
 }
예제 #3
0
 public function testSymmetricEncryption()
 {
     $keyPair1 = ECC::generateKeyPair();
     $keyPair2 = ECC::generateKeyPair();
     $symmetricKeyA = $keyPair1->calculateSymmetricKey($keyPair2->getPublicKey());
     $symmetricKeyB = $keyPair2->calculateSymmetricKey($keyPair1->getPublicKey());
     $this->assertEquals($symmetricKeyA, $symmetricKeyB);
     // if I wanna encrypt data only for myself to see
     $myKey = $keyPair1->calculateSymmetricKey();
     $iv = AES::generateInitializationVector();
     $original = 'Hello World!';
     $encrypted = AES::encrypt($original, $myKey, $iv);
     $decrypted = AES::decrypt($encrypted, $myKey, $iv);
     $this->assertEquals($original, $decrypted, 'encryption works');
 }