/** * Decrypt a string using asymmetric cryptography * Wraps SymmetricCrypto::decrypt() * * @param string $source Ciphertext * @param EncryptionSecretKey $ourPrivateKey Our private key * @param EncryptionPublicKey $theirPublicKey Their public key * @param boolean $raw Don't hex decode the input? * @return string */ public static function decrypt(string $source, EncryptionSecretKey $ourPrivateKey, EncryptionPublicKey $theirPublicKey, bool $raw = false) : string { $ecdh = new EncryptionKey(self::getSharedSecret($ourPrivateKey, $theirPublicKey)); $ciphertext = SymmetricCrypto::decrypt($source, $ecdh, $raw); unset($ecdh); return $ciphertext; }
/** * Decrypt a string using asymmetric cryptography * Wraps SymmetricCrypto::decrypt() * * @param string $ciphertext The message to decrypt * @param EncryptionSecretKey $ourPrivateKey Our private key * @param EncryptionPublicKey $theirPublicKey Their public key * @param mixed $encoding Which encoding scheme to use? * @return HiddenString The decrypted message */ public static function decrypt(string $ciphertext, EncryptionSecretKey $ourPrivateKey, EncryptionPublicKey $theirPublicKey, $encoding = Halite::ENCODE_BASE64URLSAFE) : HiddenString { $sharedSecretKey = new EncryptionKey(self::getSharedSecret($ourPrivateKey, $theirPublicKey)); $plaintext = SymmetricCrypto::decrypt($ciphertext, $sharedSecretKey, $encoding); unset($sharedSecretKey); return $plaintext; }