我目前正在尝试将 java 代码移植到 object-c。然而,我在代码中遇到了 CBCBlockCipherMac.update 和 CBCBlockCipherMac.doFinal 但不明白这些方法的作用以及它们是如何工作的。混淆点是一个 21 个字符的字符串被转换为字节并传递给这个方法,输出是一个 [4] 字节的字符串。有人请向我解释这种方法是如何工作的。示例代码附在下面。请逐步解释此方法的内容:
public String getMyMac("Thisstringis21inlength")
{
byte [] macKey = {0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10}
byte[] macBytes = new byte[4];
CBCBlockCipherMac macCipher = new CBCBlockCipherMac(new DESedeEngine());
DESedeParameters keyParameters = new DESedeParameters(macKey);
DESedeEngine engine = new DESedeEngine();
engine.init(true, keyParameters);
macCipher.init(keyParameters);
byte[] macDataBytes = macData.getBytes();
macCipher.update(macDataBytes, 0, macData.length());
macCipher.doFinal(macBytes, 0);
byte[] encodedMacBytes = Hex.encode(macBytes);
String mac = new String(encodedMacBytes);
return mac;
}