using namespace std; #include "SM4.h" #include "../mms/db_interface.h" //////////////////////////////////////////////////////////////////////////////////////////////////// void GetSM4Code(unsigned char* pSerise,char* pKey,char* output) { int i=0; unsigned char szKey[16+1] = {0}; unsigned char input[16+1] = {0}; time_t now_secs = apr_time_sec(apr_time_now()); #if 0 systime_t tm; memset(&tm,0,sizeof(systime_t)); tm.year = 2017; tm.mon = 5; tm.mday =29; tm.hour = 15; tm.min = 16; tm.sec = 20; now_secs = apr_time_sec(getTicksOfSystemTime(&tm)); apr_snprintf(pSerise,sizeof(pSerise),"%s","0123456789"); apr_snprintf(pKey,sizeof(pKey),"%s","epri.sgcc.com.cn"); //应生成加密密文 “FACCAB57B27FD9BD1627506EF751EE61” #endif int seriseLen = strlen((const char*)pSerise); int keyLen = strlen(pKey); time_t t = now_secs ;// -8*60*60; //调整时区 unsigned char* pTime = (unsigned char*)&t; unsigned char* p_u_key = (unsigned char*)pKey; input[0] = pTime[3]; input[1] = pTime[2]; input[2] = pTime[1]; input[3] = pTime[0]; for (i = 0; i < 12; i++) { if(i 0 && plain_buf[plain_len - 1] == 0x00) { plain_len--; } memcpy(plaintext_out, plain_buf, plain_len); plaintext_out[plain_len] = '\0'; return 0; }