小编Nub*_*per的帖子

自Android 6 Marshmallow以来,javax.crypto.Cipher的工作方式不同

我已成功使用javax.crypto.Cipher.getInstance("DESede/CBC/NoPadding")在Android上使用DESFire卡进行身份验证(遵循以下示例:https://stackoverflow.com/a/14160507/2095694 ).它已经在Android 4到5的几个设备上工作,但是我的Nexus 7停止工作,更新到6 Marshmallow(和6.0.1).在更新之前,它一直在使用同一设备.

似乎Cipher的工作方式不同,为相同的密钥和数据提供了不同的结果.运行以下代码......

public static void testCipher() throws Exception
{
    byte[] KEY =
            new byte[]{
                    (byte) 0x0C, (byte) 0x09, (byte) 0x03, (byte) 0x0E,
                    (byte) 0x05, (byte) 0x0A, (byte) 0x0D, (byte) 0x02,
                    (byte) 0x03, (byte) 0x0A, (byte) 0x09, (byte) 0x0B,
                    (byte) 0x06, (byte) 0x10, (byte) 0x04, (byte) 0x10
            };

    byte[] DATA =
            new byte[]{
                    (byte) 0x29, (byte) 0xDA, (byte) 0xC0, (byte) 0xC4,
                    (byte) 0xB8, (byte) 0x47, (byte) 0x13, (byte) 0xA2};

    byte[] newByte8 = new byte[8]; //Zeroes …
Run Code Online (Sandbox Code Playgroud)

java android openssl javax.crypto android-6.0-marshmallow

6
推荐指数
2
解决办法
1942
查看次数