小编Ngu*_*ong的帖子

如何使用 Android 的身份验证标签进行 GCM 加密

我想制作一个通过 GCM 模式与 Android 身份验证标签加密数据的函数。这是我的源代码:

public static byte[] GCMEncrypt(String hexKey, String hexIV, byte[] aad) throws Exception {
        byte[] aKey = hexStringToByteArray(hexKey);
        byte[] aIV = hexStringToByteArray(hexIV);
        Key key = new SecretKeySpec(aKey, "AES");
        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, key, new GCMParameterSpec(16 * Byte.SIZE, aIV));
        cipher.updateAAD(aad);
        byte[] encrypted = cipher.doFinal(aKey);
        return encrypted;
    }
Run Code Online (Sandbox Code Playgroud)

如何将身份验证标签插入此代码中?

encryption android aes-gcm

2
推荐指数
1
解决办法
4507
查看次数

标签 统计

aes-gcm ×1

android ×1

encryption ×1