/**
  * @return string
  *   Ciphertext.
  */
 public function encode()
 {
     $secret = AesHelper::createSecret();
     $rsaCiphertext = self::getRsa($this->appPubKey, 'public')->encrypt($secret);
     if (strlen($rsaCiphertext) !== Constants::RSA_MSG_BYTES) {
         throw new InvalidMessageException("RSA ciphertext has incorrect length");
     }
     list($body, $signature) = AesHelper::encryptThenSign($secret, json_encode($this->data));
     return self::NAME . Constants::PROTOCOL_DELIM . $this->appId . Constants::PROTOCOL_DELIM . base64_encode($rsaCiphertext) . Constants::PROTOCOL_DELIM . $signature . Constants::PROTOCOL_DELIM . $body;
 }
Exemple #2
0
 /**
  * @return string
  * @throws InvalidMessageException
  */
 public function encode()
 {
     list($body, $signature) = AesHelper::encryptThenSign($this->secret, json_encode($this->data));
     return self::NAME . Constants::PROTOCOL_DELIM . $this->cxnId . Constants::PROTOCOL_DELIM . $signature . Constants::PROTOCOL_DELIM . $body;
 }