Last active
September 25, 2019 08:10
-
-
Save mahadirz/2d8b802ede183637f30be2f5a530f0f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN PUBLIC KEY----- | |
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmKdQSV+JwuIQF+t1iISu | |
kHNffIDWMcr6v8L9CI1U+9LOF1xNPw7IlhubU+nLWUqGxKnFfadkB7lQCthoK+lb | |
wbVCUmUXx3vao8N61BWwWLJtlvZdp5Pz2oMQzadzIU4swzIZtTg3uPHtx+p3y5Yc | |
EKkDk3hMcEPWLzvIxSmgDTlI8HSehX7QCM29hXUpl9iXXnAAcipXQtOktmWaU731 | |
X4SMs93XIFlW2ujyde7zvd3/XTmQWTwYPQhk+OyYIBRFWijOrXGp9q5Vbz5Z+XHY | |
1esaH64xfiZZON6xLAWqh3AadqXSEJy0gqmg2MOu0CD1RgPT+mAiVXbayHWe3GnY | |
bwIDAQAB | |
-----END PUBLIC KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//signed data | |
$data = 's3://my-bucket-name/path/a/b/c.csv'; | |
// signed signature generated from private key | |
$signature = "JRcF4pkIHDSiALk/wulQaomLjSX95hrhke7Edcce8vXBxQuwpoXUw/tf0tIWAs+bMU+8LTgB7eQIWhKDj8A49FOd2C8Ez+2bSozWZdrGpYVJ1d5BmwYfKMMLmLZm/wnXwNomuuCQTsB+vSDuWj4Yq4j8d3bU8A7+KERJpQM2ZdWu2XBs/vmpjSG4JYcwf2OcZuduDCsIBTR0tAiqr2hOZnsSIDYQ9v6Fs950hmCTBraCxbPqgcrMFcTgQPCR/ZEQ/oUjuZLN/kteF+1XbmMmKnJ/0fs/542TkKU02nMJUaYqFKtr2CIYVMvpQbjO3JOC+hmwKW8mekfaekkoAf+Mhw=="; | |
// read public key from local storage | |
$c = file_get_contents("signing.pub"); | |
$public_key_res = openssl_pkey_get_public($c); | |
// verify signature is signed for the $data | |
$ok = openssl_verify($data, $signature, $public_key_res, OPENSSL_ALGO_SHA1); | |
if ($ok == 1) { | |
echo "the data is from legit sender"; | |
} elseif ($ok == 0) { | |
echo "someone try to hijack"; | |
} else { | |
echo "error: " . openssl_error_string(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment