VC编译一段程度,一直出现错误
// EVP_Encrypt.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
void tEVP_Encrypt()
{
unsigned char key[EVP_MAX_KEY_LENGTH]; //密钥
unsigned char iv[EVP_MAX_KEY_LENGTH]; //初始化向量
EVP_CIPHER_CTX ctx; //EVP算法上下文
unsigned char out[1024]; //输出密文缓冲区
int outl; //密文长度
int outltmp;
char *msg="Hello OpenSSL"; //待加密的数据
int rv;
int i;
//设置key和iv(可以采用随机数,也可以由用户输入)
for(i=0;i<24;i++)
{
key[i]=i;
}
for(i=0;i<8;i++)
{
iv[i]=i;
}
//初始化密码算法结构体
EVP_CIPHER_CTX_init(&ctx);
//设置算法和密钥以及初始化向量
rv=EVP_EncryptInit_ex(&ctx,EVP_des_ede3_cbc(),NULL,key,iv);
if(rv!=1)
{
printf("ERR\n");
return;
}
//数据加密
rv=EVP_EncryptUpdate(&ctx,out,&outl,msg,strlen(msg));
if(rv!=1)
{
printf("ERR\n");
return;
}
//结束数据加密,把剩余数据输出
rv=EVP_EncryptFinal_ex(&ctx,out+outl,&outltmp);
if(rv!=1)
{
printf("ERR\n");
return;
}
outl=outl+outltmp;
printf("原文为:%s\n",msg);
//打印输出密文
printf("密文长度:%d\n 密文数据: \n",outl);
for(i=0;i<outl;i++)
{
printf("0x%02x",out[i]);
}
printf("\n");
}
int main()
{
OpenSSL_add_all_algorithms();
tEVP_Encrypt();
return 0;
}
程序如上,编译后出现
--------------------Configuration: EVP_Encrypt - Win32 Debug--------------------
Compiling...
EVP_Encrypt.cpp
d:\myprojects\evp_encrypt\evp_encrypt.cpp(44) : error C2664: 'EVP_EncryptUpdate' : cannot convert parameter 4 from 'char *' to 'const unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
EVP_Encrypt.exe - 1 error(s), 0 warning(s)
好像是数据类型不能互相转换的问题,请问该如何处理?