OpenSSL/GMSSL EVP接口说明——1.1 对称算法加密解密使用步骤

1.1 加密解密使用步骤

表1.1 加密解密使用步骤

加密

解密

备注

1

EVP_CIPHER_CTX_init(

&ctx);

EVP_CIPHER_CTX_init(

&ctx);

2

EVP_EncryptInit_ex(

&ctx, cipher, NULL, key, iv);

EVP_DecryptInit_ex(

&ctx, cipher, NULL, key, iv);

cipher 可以是EVP_sm4_ecb()、EVP_sm4_cbc()等

3

EVP_EncryptUpdate(

&ctx,p_out,&outlen,p_in,inlen);

EVP_DecryptUpdate(

&ctx,p_out,&outlen,p_in,inlen);

消息可多次添加

4

EVP_EncryptFinal_ex(

&ctx,p_out,&outlen);

EVP_DecryptFinal_ex(

&ctx,p_out,&outlen);

◆本步还会输出密文/明文;

◆ctlen >= ptlen;

◆填充方式为每个被填充的字节设置为填充长度

5

EVP_CIPHER_CTX_cleanup(&ctx);

EVP_CIPHER_CTX_cleanup(&ctx);

posted @ 2023-04-04 20:42  艾米的爸爸  阅读(2)  评论(0)    收藏  举报  来源