什么是 Google Play 完整性常量 AES_KEY_SIZE_BYTES、AES_KEY_TYPE 和 EC_KEY_TYPE

abh*_*ure 4 google-play-integrity-api

根据官方文档 ( https://developer.android.com/google/play/integrity/verdict ) 解密和验证 Google Play完整性判决时,共享的代码片段/样本使用以下常量:AES_KEY_SIZE_BYTESAES_KEY_TYPEEC_KEY_TYPE

但这些的价值却从未被提及。有人可以帮忙吗,这些价值观是什么?

abh*_*ure 7

在互联网上搜索了几个小时后,我发现了一个 YouTube 视频(获取并解码完整性判决 | 迁移到 Play Integrity API 的第 3 步)(显然不是来自 Google),它给了我所需的答案。以下是这些常量的值:

AES_KEY_SIZE_BYTES:decryptionKeyBytes.length AES_KEY_TYPE:AES EC_KEY_TYPE:EC

所以你的最终代码应该是这样的:

package com.example.sample
...
...
import org.apache.commons.codec.binary.Base64;
import org.jose4j.jwe.JsonWebEncryption;
import org.jose4j.jws.JsonWebSignature;
import org.jose4j.jwx.JsonWebStructure;
import org.jose4j.lang.JoseException;
...
...


// base64OfEncodedDecryptionKey is provided through Play Console.
byte[] decryptionKeyBytes =
    Base64.decode(base64OfEncodedDecryptionKey, Base64.DEFAULT);

// Deserialized encryption (symmetric) key.
SecretKey decryptionKey =
    new SecretKeySpec(
        decryptionKeyBytes,
        /* offset= */ 0,
        decryptionKeyBytes.length,
        "AES");

// base64OfEncodedVerificationKey is provided through Play Console.
byte[] encodedVerificationKey =
    Base64.decode(base64OfEncodedVerificationKey, Base64.DEFAULT);
// Deserialized verification (public) key.
PublicKey verificationKey =
    KeyFactory.getInstance("EC")
        .generatePublic(new X509EncodedKeySpec(encodedVerificationKey));
Run Code Online (Sandbox Code Playgroud)

如果您使用 Maven,请确保添加了这些依赖项:

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-playintegrity</artifactId>
    <version>v1-rev20220904-2.0.0</version>
</dependency>
<dependency>
    <groupId>org.bitbucket.b_c</groupId>
    <artifactId>jose4j</artifactId>
    <version>0.8.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)