Takes two resource handles and encrypts the contents of the first,
writing the ciphertext into the second.
public static encryptResource ( resource $inputHandle, resource $outputHandle, Defuse\Crypto\Key $key ) | ||
$inputHandle | resource | |
$outputHandle | resource | |
$key | Defuse\Crypto\Key |
/** * Encrypts a stream. * * @param resource $resource The stream to encrypt. * * @return resource The encrypted stream. */ private function encryptStream($resource) { $out = fopen('php://temp', 'r+b'); File::encryptResource($resource, $out, $this->key()); rewind($out); return $out; }
/** * Encrypts a string. * * @param string $contents The string to encrypt. * * @return string The encrypted string. */ protected function encrypt($contents) { $resource = fopen('php://memory', 'r+b'); File::writeBytes($resource, $contents); rewind($resource); $out = fopen('php://memory', 'r+b'); File::encryptResource($resource, $out, $this->key); rewind($out); return stream_get_contents($out); }