Last active
December 11, 2015 12:38
-
-
Save stephenjtong/4601588 to your computer and use it in GitHub Desktop.
PHP server side google play signature validation
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 | |
$prefix = "-----BEGIN PUBLIC KEY-----\n"; | |
$surfix = '-----END PUBLIC KEY-----'; | |
$key = "your google play pub key"; | |
$key =$prefix . chunk_split($key, 64, "\n") . $surfix; | |
$key = openssl_get_publickey($key); | |
if (false === $key) { | |
echo "invalid public key\n"; | |
return; | |
} | |
$data_str = '{data string returned by google play}'; | |
$signature = '{signature returned by google play}'; | |
$validate = openssl_verify($data_str, base64_decode($signature), $key); | |
if(1 != $validate){ //invalid signature | |
echo "mojo_invalid_signature\n"; | |
} else { | |
echo "success\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment