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