Iphone:如何验证消息验证码(Mac)

012*_*346 5 iphone authentication code-signing aes objective-c

我有这样的Java代码:

public static byte[] generateMac(byte[] key, byte[] cipherText,int offset,int length,int mac_size_bits)
{
    byte[] result = null;
    KeyParameter keyParam = null;
    try {
        keyParam = new KeyParameter(key);
        CBCBlockCipherMac blockCipherMac = new CBCBlockCipherMac(new AESEngine(),mac_size_bits);
        result = new byte[blockCipherMac.getMacSize()];
        blockCipherMac.init(keyParam);
        blockCipherMac.update(cipherText, offset, length);
        blockCipherMac.doFinal(result, 0);
    } catch (Exception e) {
        // System.out.println(e);
        return null;
    } finally {
        keyParam = null;
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

在iPhone上,我这样涂鸦:

- (NSData *)generateMac:(NSData *)key cipherText:(NSData *)cipherText offset:(int)offset length:(int)length mac_size_bits:(int)mac_size_bits

我的问题是,我应该使用哪种方法CBCBlockCipherMac,keyparameters在iPhone中有人可以帮助我吗?

Dai*_*jan 1

它的 MAC 加密——据我所知,IOS 上没有一次性替代/等效的方法

请参阅原始文档docs 和 wikipedia wiki

了解该算法的工作原理,然后使用 CommonCrypto 复制它

--抱歉没有更好的主意