mac下用c语言md5加密

本文介绍了在Mac环境下,利用CommonCrypto库通过两种方法实现C语言的MD5加密过程。
摘要由CSDN通过智能技术生成

今天在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);
    
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值