似乎CBC-MAC算法有6种变化.我一直在努力匹配PINPad 1000SE上的MAC算法[每本手册都是ISO 9797-1算法1].
我从这里开始了一个很好的开始.
我将算法编码如下:
public static byte[] CalculateMAC(this IPinPad pinpad, byte[] message, byte[] key)
{
//Divide the key with Key1[ first 64 bits] and key2 [last 64 bits]
var key1 = new byte[8];
Array.Copy(key, 0, key1, 0, 8);
var key2 = new byte[8];
Array.Copy(key, 8, key2, 0, 8); //64 bits
//divide the message into 8 bytes blocks
//pad the last block with "80" and "00","00","00" until it reaches 8 bytes
//if the message already can be divided …Run Code Online (Sandbox Code Playgroud) 我想知道我是否可以使用在两个客户端之间建立的共享密钥作为HMAC密钥.
我看到当它被用作CBC-MAC时存在问题,但我没有发现任何证据表明HMAC是不好的做法.
谢谢,弗拉基米尔
我想用openssl计算给定明文的CBC-MAC.我有以下明文(hexdump):
hexdump -C example.txt
00000000 4d 41 43 73 20 61 72 65 20 76 65 72 79 20 75 73 |MACs are very us|
00000010 65 66 75 6c 20 69 6e 20 63 72 79 70 74 6f 67 72 |eful in cryptogr|
00000020 61 70 68 79 21 20 20 20 20 20 20 20 20 20 20 20 |aphy! |
Run Code Online (Sandbox Code Playgroud)
如果我使用openssl的命令行函数,我得到以下解决方案:
openssl aes-256-cbc -in example.txt -K 8000000000000000000000000000000000000000000000000000000000000001 -e -iv 00 | hexdump -C
00000000 e8 e9 …Run Code Online (Sandbox Code Playgroud)