今天在Mac下弄md5加密,需要使用库CommonCrypto进行。
第一种方式:
//
// main.c
// CAESTest
//
// Created by comeontom on 14/7/31.
// Copyright (c) 2014年 comeontom. All rights reserved.
//
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonDigest.h>
//#import <CommonCrypto/CommonHMAC.h>
char cryptKey[kCCKeySizeAES128] = "O3fX{j{
{*1:r[S2w";
char hexChar(unsigned char c) {
return c < 10 ? '0' + c : 'a' + c - 10;
}
void hexString32(unsigned char *from, char *to, int length) {
for (int i = 0; i < length; ++i) {
unsigned char c = from[i];
unsigned char cHigh = c >> 4;
unsigned char cLow = c & 0xf;
to[2 * i] = hexChar(cHigh);
to[2 * i + 1] = hexChar(cLow);