日期:2014-05-16 浏览次数:21011 次
std::string Decrypt( const std::string& sInbuf, const std::string& sKey)
{
const char* inbuf = sInbuf.c_str();
unsigned char * key = (unsigned char *)sKey.c_str();
int inlen = sInbuf.length();
BIO *bio, *mbio, *cbio;
char *dst;
int outlen;
mbio = BIO_new( BIO_s_mem( ) );
cbio = BIO_new( BIO_f_cipher( ) );
BIO_set_cipher( cbio , EVP_des_ecb( ) , key , NULL , 0 );
bio = BIO_push( cbio , mbio );
BIO_write( bio , inbuf , inlen );
BIO_flush( bio );
outlen = BIO_get_mem_data( mbio , (char **) & dst );
dst[outlen] = '\0';
string sResult = dst;
BIO_free_all( bio );
return sResult;
}