Skip to content

Instantly share code, notes, and snippets.

@stephenjtong
Last active December 11, 2015 12:38
Show Gist options
  • Save stephenjtong/4601588 to your computer and use it in GitHub Desktop.
Save stephenjtong/4601588 to your computer and use it in GitHub Desktop.
PHP server side google play signature validation
<?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