Skip to content

Instantly share code, notes, and snippets.

@genkovich
Created May 1, 2022 12:16
Show Gist options
  • Save genkovich/2e7282100f545118380050685f6af763 to your computer and use it in GitHub Desktop.
Save genkovich/2e7282100f545118380050685f6af763 to your computer and use it in GitHub Desktop.
sign.php
<? php
# On sender side:
$data = 'Beer::PHP';
$hash = hash(CRYPT_SHA256, $data);
$sign = encryptByPrivateKey($hash);
$result = send('receiver_address', [
'data' => $data,
'sign' => $sign
]);
# On receiver side:
[$data, $sign] = getFromRequest();
$hash = hash(CRYPT_SHA256, $data);
$decryptedHash = decryptByPublicKey($sign);
if ($hash !== $decryptedHash) {
// Something went wrong
}
// $data is valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment