Android 中使用AES-CMAC数据加密

本文详细介绍了在Android环境中如何实现AES-CMAC数据加密,包括计算L、K1、K2的关键步骤,并通过在线AES工具进行验证。
摘要由CSDN通过智能技术生成

一般需要分为三个步骤:

算出L的值,然后算出K1,K2的值,可以对比AES在线加密工具作为对比


    /**
     * 算法逻辑
     *
     * @param key
     * @param data
     * @return
     */
    public static byte[] Aes_Cmac01(byte[] key, byte[] data) {
        // 子密钥生成
        // 步骤1,将具有密钥K的AES-128应用于全零输入块。
        byte[] L = aesEncryptNoPadding(key, new byte[16], new byte[16]);

        Log.i(TAG, "configUUIDValue  L: " + ByteUtils.bytes2HexStr(L));
        // 步骤2,通过以下操作得出K1:
        //如果L的最高有效位等于0,则K1是L的左移1位。
        byte[] FirstSubkey = Rol(L);
        if ((L[0] & 0x80) == 0x80) {
            // 否则,K1是const_Rb的异或和L左移1位。
            FirstSubkey[15] ^= 0x87;
        }
//        Log.i(TAG, "configUUIDValue  K1: "+ ByteUtils.bytes2HexStr(FirstSubkey));
//        FirstSubkey = ByteUtils.hexStr2Bytes("AC362C7FCCE2BD996153C64B7D39A82A");

        Log.i(TAG, "configUUIDValue  K1: " + ByteUtils.bytes2HexStr(FirstSubkey));
        // 步骤3,通过以下操作得出K2:
        //如果K1的最高有效位等于0,则K2是K1左移1位
        byte[] SecondSubkey = Rol(FirstSubkey);
        if ((FirstSubkey[0] & 0x80) == 0x80) {
            // 否则,K2是const_Rb的异或,且K1左移1位
            SecondSubkey[15] ^= 0x87;
        }

//        Log.i(TAG, "configUUIDValue  K2: "+ ByteUtils.bytes2HexStr(SecondSubkey));
//        SecondSubkey = ByteUtils.hexStr2Bytes("586C58FF99C57B32C2A78C96FA7350D3");
        Log.i(TAG, "configUUIDValue  K2: " + By
详细介绍了AES-CMAC的算法的原理与实现,附有C语言写的样例程序。 以下是原文的introduction: The National Institute of Standards and Technology (NIST) has recently specified the Cipher-based Message Authentication Code(CMAC). CMAC [NIST-CMAC] is a keyed hash function that is based on a symmetric key block cipher, such as the Advanced Encryption Standard [NIST-AES]. CMAC is equivalent to the One-Key CBC MAC1 (OMAC1) submitted by Iwata and Kurosawa [OMAC1a, OMAC1b]. OMAC1 is an improvement of the eXtended Cipher Block Chaining mode (XCBC) submitted by Black and Rogaway [XCBCa, XCBCb], which itself is an improvement of the basic Cipher Block Chaining-Message Authentication Code (CBC-MAC). XCBC efficiently addresses the security deficiencies of CBC-MAC, and OMAC1 efficiently reduces the key size of XCBC. AES-CMAC provides stronger assurance of data integrity than a checksum or an error-detecting code. The verification of a checksum or an error-detecting code detects only accidental modifications of the data, while CMAC is designed to detect intentional, unauthorized modifications of the data, as well as accidental modifications. AES-CMAC achieves a security goal similar to that of HMAC [RFC-HMAC]. Since AES-CMAC is based on a symmetric key block cipher, AES, and HMAC is based on a hash function, such as SHA-1, AES-CMAC is appropriate for information systems in which AES is more readily available than a hash function. This memo specifies the authentication algorithm based on CMAC with AES-128. This new authentication algorithm is named AES-CMAC.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值