#include <openssl/evp.h>
#include <openssl/ossl_typ.h>
#include <openssl/md5.h>
#include <string.h>
int Enclicense(unsigned char* in, int inlen, unsigned char* _out)
{
int ret = 0;
unsigned char out[1024] = { 0 };
int outlen = 1024;
int _updatelen;
int tmplen;
EVP_CIPHER_CTX *evp_cipher_ctx = NULL;
evp_cipher_ctx = EVP_CIPHER_CTX_new();
if (!evp_cipher_ctx) {
ret = -1;
return ret;
}
ret = EVP_CIPHER_CTX_set_padding(evp_cipher_ctx, 1);
unsigned char _key[]= "86C63180C2806ED1";
ret = EVP_CipherInit(evp_cipher_ctx, EVP_sm4_ecb(), _key, NULL, 1);
if (1 != ret)
return ret;
_updatelen = outlen;
ret = EVP_CipherUpdate(evp_cipher_ctx, out, &_updatelen, in, inlen);
if (1 != ret)
return 0;
tmplen = outlen - _updatelen;
ret = EVP_CipherFinal(evp_cipher_ctx, &out[_updatelen], &tmplen);
outlen = _updatelen + tmplen;
CCodeChange::GetInst().HexToStr(out, outlen, (char*)_out);
return ret;
}