Skip to content

Instantly share code, notes, and snippets.

@SpringMT
Forked from ys4kw/ruby-iab.md
Created July 26, 2014 04:41
Show Gist options
  • Save SpringMT/c014d3448d63e376c018 to your computer and use it in GitHub Desktop.
Save SpringMT/c014d3448d63e376c018 to your computer and use it in GitHub Desktop.
def in_app_purchase signature, receipt_data, base64_encoded_public_key
  public_key = OpenSSL::PKey::RSA.new(base64_encoded_public_key)
  if public_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(signature), receipt_data)
    # Success
  else
    # Failure
  end
end

signature、receipt_dataは、課金成功時にGoogle Playから受け取る
(receipt_dataはjson)

base64_encoded_public_keyは、Google Playから取得する公開キーをpemにしたもの

public.pem作成

  1. public keyをpublicファイルに入力
  2. base64 -d public > public.der (osxのbase64コマンドは base64 -Dを使う)
  3. openssl rsa -inform DER -outform PEM -pubin -in public.der -out public.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment