Iphone: how to check message authentication code (Mac)

I have Java code like this:

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;
}

On the iPhone, I write it like this:

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

My question is: what method should I use for CBCBlockCipherMac, keyparameterson the iPhone, can anyone help me?

+5
source share
1 answer

its MAC encryption - AFAIK no one-time replacement / equivalent on iOS

see original docs and wikipedia wiki docs

learn how the algorithm works, and then replicate it with CommonCrypto

- sorry, no better idea

+1
source

All Articles