Skip to content Skip to sidebar Skip to footer

In-app Billing Verification. Does Server Side Code Example Exist Somewhere?

A lot of people ask how to write server side code for in-app billing verificartion. Can anybody publish such code? Or know where such code is. How to install in on the server? The

Solution 1:

Actually it's pretty easy, you just need a small function like this in PHP:

function checkPayment($data, $signature)
{
    $base64EncodedPublicKey = "yourBase64PublicKey";
    $openSslFriendlyKey = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($base64EncodedPublicKey, 64, "\n") .  "-----END PUBLIC KEY-----";
    $publicKeyId = openssl_get_publickey($openSslFriendlyKey);

    $result =  openssl_verify ($data, base64_decode($signature), $publicKeyId, OPENSSL_ALGO_SHA1);

    /*
    if ($result == 1) {
        echo"Success";
    } elseif ($result == 0) {
        echo"Verification Failed";
    }
    */

    return$result;
}

Solution 2:

Here is (uncompleted) python example:

from M2Crypto import BIO, RSA, EVP

ANDROID_PK = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgmZW0GxWr0v1ndLfxHbV2ruWcmQ
<some lines skipped>
cwWjx5sWSahVp0M5aYRysSkGGjSxe1wIDAQAB
-----END PUBLIC KEY-----"""defvalidate_google_play_signature(signed_data, signature_base64, public_key):
    # http://stackoverflow.com/a/546476/227024
    bio = BIO.MemoryBuffer(public_key)
    rsa = RSA.load_pub_key_bio(bio)
    pubkey = EVP.PKey()
    pubkey.assign_rsa(rsa)

    pubkey.reset_context(md="sha1")
    pubkey.verify_init()
    pubkey.verify_update(signed_data)

    signature = base64.b64decode(signature_base64)
    returnbool(pubkey.verify_final(signature))

Post a Comment for "In-app Billing Verification. Does Server Side Code Example Exist Somewhere?"