Java 中的 CMAC-AES (RFC 4493) 计算
CMAC-AES (RFC 4493) calculation in Java
我有密钥和数据:
现在如何根据这些参数计算 CMAC?
更多信息:
根据 NIST 特别出版物 800-38B 中描述的 CMAC 标准,MACs 是使用 AES 作为基础分组密码计算的。但我很难在 java.
中找到正确的 MAC 计算示例
编辑
this link 非常适合这个。我需要 Java 个样本。
如果有人在这里寻找 CMAC AES 计算,它正在使用 Bouncy Castle:
public void getCMAC()
throws Exception {
byte[] msg = new byte[]{(byte) 0xA3, (byte) 0x00, (byte) 0x00, (byte) 0x35, (byte) 0xE7, (byte) 0x58,
(byte) 0xC6, (byte) 0x09, (byte) 0x00, (byte) 0x4F, (byte) 0x44, (byte) 0x36, (byte) 0xF0,
(byte) 0xEA, (byte) 0x31, (byte) 0x9A, (byte) 0xF4, (byte) 0x31, (byte) 0xE1,
(byte) 0x98, (byte) 0xBC, (byte) 0x41, (byte) 0xA0, (byte) 0x67, (byte) 0xD1};
byte[] keydata = new byte[]{(byte) 0x67, (byte) 0x1B, (byte) 0x9D, (byte) 0x1D, (byte) 0xC1, (byte) 0x54,
(byte) 0x74, (byte) 0xA2, (byte) 0x5C, (byte) 0xB1, (byte) 0x77, (byte) 0xCA, (byte) 0x1A,
(byte) 0x19, (byte) 0x9F, (byte) 0x0E};
CipherParameters params = new KeyParameter(keydata);
BlockCipher aes = new AESEngine();
CMac mac = new CMac(aes);
mac.init(params);
mac.update(msg, 0, msg.length);
byte[] out = new byte[mac.getMacSize()];
mac.doFinal(out, 0);
StringBuilder s19 = new StringBuilder();
for (byte b : out) {
s19.append(String.format("%02X ", b));
}
Log.e("ecrypted Kmac :", s19.toString());
}
确保像这样添加库:
implementation 'org.bouncycastle:bcpkix-jdk15on:1.56'
我有密钥和数据:
现在如何根据这些参数计算 CMAC?
更多信息:
根据 NIST 特别出版物 800-38B 中描述的 CMAC 标准,MACs 是使用 AES 作为基础分组密码计算的。但我很难在 java.
中找到正确的 MAC 计算示例编辑 this link 非常适合这个。我需要 Java 个样本。
如果有人在这里寻找 CMAC AES 计算,它正在使用 Bouncy Castle:
public void getCMAC()
throws Exception {
byte[] msg = new byte[]{(byte) 0xA3, (byte) 0x00, (byte) 0x00, (byte) 0x35, (byte) 0xE7, (byte) 0x58,
(byte) 0xC6, (byte) 0x09, (byte) 0x00, (byte) 0x4F, (byte) 0x44, (byte) 0x36, (byte) 0xF0,
(byte) 0xEA, (byte) 0x31, (byte) 0x9A, (byte) 0xF4, (byte) 0x31, (byte) 0xE1,
(byte) 0x98, (byte) 0xBC, (byte) 0x41, (byte) 0xA0, (byte) 0x67, (byte) 0xD1};
byte[] keydata = new byte[]{(byte) 0x67, (byte) 0x1B, (byte) 0x9D, (byte) 0x1D, (byte) 0xC1, (byte) 0x54,
(byte) 0x74, (byte) 0xA2, (byte) 0x5C, (byte) 0xB1, (byte) 0x77, (byte) 0xCA, (byte) 0x1A,
(byte) 0x19, (byte) 0x9F, (byte) 0x0E};
CipherParameters params = new KeyParameter(keydata);
BlockCipher aes = new AESEngine();
CMac mac = new CMac(aes);
mac.init(params);
mac.update(msg, 0, msg.length);
byte[] out = new byte[mac.getMacSize()];
mac.doFinal(out, 0);
StringBuilder s19 = new StringBuilder();
for (byte b : out) {
s19.append(String.format("%02X ", b));
}
Log.e("ecrypted Kmac :", s19.toString());
}
确保像这样添加库:
implementation 'org.bouncycastle:bcpkix-jdk15on:1.56'