src/Api.php
public function encrypt($data) {
    $plaintext = json_encode($data);

    $public_key = $this->getPublicKey();

    $result = openssl_seal($plaintext, $message, $keys, array($public_key));

    if ($result === FALSE || empty($keys[0]) || empty($message) || $message === $plaintext) {
      throw new EncryptionException('Unable to encrypt a message: ' . openssl_error_string());
    }

    $envelope = (object) array(
      'key' => base64_encode($keys[0]),
      'message' => base64_encode($message),
    );

    return base64_encode(json_encode($envelope));
  }
public function encrypt($data) {
    $plaintext = json_encode($data);

    $public_key = $this->getPublicKey();

    $result = openssl_seal($plaintext, $message, $keys, array($public_key));

    if ($result === FALSE || empty($keys[0]) || empty($message) || $message === $plaintext) {
      throw new EncryptionException('Unable to encrypt a message: ' . openssl_error_string());
    }

    $envelope = (object) array(
      'key' => base64_encode($keys[0]),
      'message' => base64_encode($message),
    );

    return base64_encode(json_encode($envelope));
  }
public function encrypt ( $ data ) { $ plaintext = json_encode ( $ data ) ; $ public_key = $ this -> getPublicKey ( ) ; $ result = openssl_seal ( $ plaintext , $ message , $ keys , array ( $ public_key ) ) ; if ( $ result === FALSE || empty ( $ keys [ 0 ] ) || empty ( $ message ) || $ message === $ plaintext ) { throw new EncryptionException ( 'Unable to encrypt a message: ' . openssl_error_string ( ) ) ; } $ envelope = ( object ) array ( 'key' => base64_encode ( $ keys [ 0 ] ) , 'message' => base64_encode ( $ message ) , ) ; return base64_encode ( json_encode ( $ envelope ) ) ; }
Encrypt a plaintext message.

@param mixed $data
The data to encrypt for transport.

@return string
The encoded message

@throws EncryptionException
If there is a problem with the encryption process.
@throws WardenBadResponseException
If the response status from Warden was not 200 when retrieving the
public key.
Encrypt a plaintext message .