Skip to content

Commit 26555ec

Browse files
committed
Fix Encrypted Transactions
1 parent 6f8f1df commit 26555ec

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/connection.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,40 @@ private function _submit($content)
137137
*/
138138
public function send($txBody)
139139
{
140+
// Convert Body to string
141+
$content = json_encode($txBody, JSON_UNESCAPED_SLASHES);
142+
140143
// Encrypted Connection?
141144
if ($this->_pem) {
142-
// Encrypt with the nodes public address
143-
openssl_public_encrypt(
144-
json_encode($txBody, JSON_UNESCAPED_SLASHES),
145-
$encrypted,
146-
$this->_pem,
147-
OPENSSL_PKCS1_OAEP_PADDING
148-
);
149-
150-
// Submit Transaction as Base54 Encoded body
151-
return $this->_submit(base64_encode($encrypted));
145+
146+
// Split String into encryptable chunks
147+
$chunks = str_split($content, 116);
148+
149+
// Stores concatenated encrypted chunks
150+
$encryptedContent = "";
151+
152+
// Loop chunks and encrypt
153+
foreach ($chunks as $chunk) {
154+
if (openssl_public_encrypt(
155+
$chunk,
156+
$encrypted,
157+
$this->_pem,
158+
OPENSSL_PKCS1_PADDING
159+
)
160+
) {
161+
// Append encryption
162+
$encryptedContent .= $encrypted;
163+
} else {
164+
throw new \Exception("Failed to encrypt");
165+
}
166+
}
167+
168+
// Update Content with base64 encoded encrypted
169+
$content = base64_encode($encryptedContent);
152170
}
153171

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

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

0 commit comments

Comments
 (0)