18
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android in-app-billing のデータが改ざんされていないかの検証

Last updated at Posted at 2014-09-12

メモです。表題の通り。

利用される値

  • license_key
    ディベロッパーコンソール > アプリ > サービスとAPI の「バイナリに追加する Base64 エンコードの RSA 公開鍵です。スペースはすべて削除してください。」の下にある文字列
  • purchase_data
    購入時のIntentから INAPP_PURCHASE_DATA で取り出せる値
  • signature
    購入時のIntentから INAPP_DATA_SIGNATURE で取り出せる値

検証コード

def verify(data, sign)
  verifier.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(sign), data)
end

def verifier
  @_verifier ||= OpenSSL::PKey::RSA.new(Base64.decode64(license_key))
end

if ! verify(purchase_data, signature)
  raise 'データが改ざんされています'
end
18
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?