Skip to content

Commit

Permalink
Fix Encrypted Transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmWalker committed Nov 2, 2018
1 parent 6f8f1df commit 26555ec
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,40 @@ private function _submit($content)
*/
public function send($txBody)
{
// Convert Body to string
$content = json_encode($txBody, JSON_UNESCAPED_SLASHES);

// Encrypted Connection?
if ($this->_pem) {
// Encrypt with the nodes public address
openssl_public_encrypt(
json_encode($txBody, JSON_UNESCAPED_SLASHES),
$encrypted,
$this->_pem,
OPENSSL_PKCS1_OAEP_PADDING
);

// Submit Transaction as Base54 Encoded body
return $this->_submit(base64_encode($encrypted));

// Split String into encryptable chunks
$chunks = str_split($content, 116);

// Stores concatenated encrypted chunks
$encryptedContent = "";

// Loop chunks and encrypt
foreach ($chunks as $chunk) {
if (openssl_public_encrypt(
$chunk,
$encrypted,
$this->_pem,
OPENSSL_PKCS1_PADDING
)
) {
// Append encryption
$encryptedContent .= $encrypted;
} else {
throw new \Exception("Failed to encrypt");
}
}

// Update Content with base64 encoded encrypted
$content = base64_encode($encryptedContent);
}

// Normal Transaction Send as JSON
$response = $this->_submit(json_encode($txBody, JSON_UNESCAPED_SLASHES));
$response = $this->_submit($content);

// Did we get a response?
if ($response && $response->{'$umid'}) {
Expand Down

0 comments on commit 26555ec

Please sign in to comment.