美文网首页
iOS AES Cryptography note

iOS AES Cryptography note

作者: alex_wood | 来源:发表于2017-04-28 16:35 被阅读0次
  • hex string of salt and iv(initial vector) have to be converted into bytes, of which the length will be half of the original string.
    - (NSData *)dataFromHexString {
    const char *chars = [self UTF8String];
    int i = 0, len = self.length;

             NSMutableData *data = [NSMutableData dataWithCapacity:len / 2];
             char byteChars[3] = {'\0','\0','\0'};
             unsigned long wholeByte;
    
             while (i < len) {
                 byteChars[0] = chars[i++];
                 byteChars[1] = chars[i++];
                 wholeByte = strtoul(byteChars, NULL, 16);
                 [data appendBytes:&wholeByte length:1];
             }
    
             return data;
         }
    
  • Details about CommonCrypto

  • IV has to be 16 bytes.

  • On iOS, you should be using the CCCrypt*() functions for AES.

相关文章

网友评论

      本文标题:iOS AES Cryptography note

      本文链接:https://www.haomeiwen.com/subject/ichazttx.html