Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone:how toValidate message authentication code(Mac)

I have a 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 am scribbling 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, which method should I use for CBCBlockCipherMac, keyparameters in iPhone can anyone help me please?

like image 321
012346 Avatar asked Nov 13 '22 23:11

012346


1 Answers

its MAC encryption -- AFAIK there is no one-shot replacement/equivalent on IOS

see original docs docs and wikipedia wiki

learn how the algo works and then replicate it using CommonCrypto

--sorry no better idea

like image 197
Daij-Djan Avatar answered Nov 15 '22 12:11

Daij-Djan