C + + interface of the openssl+ algorithm in its own package

Source: Internet
Author: User
Tags decrypt

Digest
#ifndef _digestcalc_h#define _digestcalc_h/**********************************/* Use example: (SM3 algorithm)/*digestcalc hashcl;/* Hashcl. Init (DIGESTCALC::ALG_ID::SM3);/*hashcl. Update (IN,INL);/* vector<unsigned int> out (hashcl. Gethashlength ());/*hashcl. Final (Out.data ());/**********************************/class _digestcalc;class Digestcalc{public:class alg_id{ Friend class digestcalc;explicit alg_id (int i): _id (i) {}int _id;public:static const alg_id sm3;static const ALG_ID Sha;sta  Tic Const alg_id sha1;static const ALG_ID sha224;static const ALG_ID sha256;static const ALG_ID sha384;static const ALG_ID sha512;static Const ALG_ID md2;static const ALG_ID md4;static const ALG_ID md5;static const ALG_ID rc2;static const ALG_I D rc4;static Const alg_id rc5;static const ALG_ID dsa;static const ALG_ID mdc2;static const ALG_ID ECDSA;}; Public:digestcalc (); ~digestcalc ();//@param ALG Algorithm ID//@return error returned false, Truebool Init (alg_id ID) successfully returned;//@param in Input buffer address//@param INL input data length//@return error returned false, successfully returned Truebool UPDATE (const unsigned char *in,unsigned int inl);//increases the computed data. @param out output buffer address//@return Error returns false, Truebool Final (unsigned char *out) is returned successfully, and the hash result is computed and stored in the out-pointing buffer. int gethashlength () const;//Call this function to get the hash length before calling final, ensuring that the hash buffer is long enough. Private:_digestcalc *_impl;digestcalc (const DIGESTCALC &);D igestcalc &operator= (const DIGESTCALC &);}; #endif

  

Cipher
#ifndef _ciphercalc_h#define _ciphercalc_h/**********************************/* Use example: (SM4 algorithm CBC mode encryption)/*ciphercalc Cipher;/*outl=0;/*cipher. Init (ciphercalc::alg_id::sm4_cbc,key,iv,ciphercalc::encrypt,ciphercalc::P admode::openssl_padding);/*cipher. Update (IN,INL,OUT,&AMP;OUTL);/*cipher. Final (OUT+OUTL,&AMP;OUTL);/**********************************/class _ciphercalc;class CipherCalc{public:// Represents a cryptographic operation or decryption operation class Encmode{friend class Ciphercalc;int enc;explicit encmode (int x): Enc (x) {}public:static const Encmode encrypt;//encryption static const Encmode decrypt;//decryption};//indicates how the data is populated class Padmode{friend class Ciphercalc;int padding; explicit Padmode (int x):p Adding (x) {}public:static const padmode no_padding;//The user fills the data themselves, guaranteeing that the data length is an integer multiple of the grouping length, otherwise the operation is faulted. The static const Padmode OPENSSL_PADDING;//OPENSSL Fill algorithm fills the data to an integer multiple of the packet length. If the length of the data itself is an integer multiple of the group//length, a grouping is appended. All byte values that are populated are equal to the length of the appended data. };//indicates which symmetric algorithm class Alg_id{friend class ciphercalc;explicit alg_id (int id) is used: _id (ID) {}int _id;public:static const ALG_ID sm4_ecb;//State SM4 ECB mode static const ALG_ID sm4_cbc;//State SM4 CBC mode static const ALG_ID des_cfb;static const ALG_ID des_cfb1;static const ALG_ID des_cfb8;static const A lg_id des_ede_cfb;static const ALG_ID des_ede3_cfb;static const ALG_ID des_ede3_cfb1;static const ALG_ID DES_EDE3_CFB8; static const alg_id Des_ofb;static const ALG_ID des_ede_ofb;static const ALG_ID des_ede3_ofb;static const ALG_ID DESX_CBC;  static const ALG_ID des_cbc;//single-des CBC mode static const ALG_ID DES_EDE_CBC; 3DES CBC mode static const ALG_ID des_ede3_cbc;static const ALG_ID des_ecb;//single-des ECB mode static const ALG_ID Des_ede;static Co     NST alg_id Des_ede3; 3DES ECB mode static const ALG_ID rc4;static const ALG_ID rc4_40;static const ALG_ID rc4_hmac_md5;static const ALG_ID idea_e cb;static Const ALG_ID idea_cfb;static const ALG_ID idea_ofb;static const ALG_ID idea_cbc;static const ALG_ID Seed_ecb;sta Tic Const alg_id seed_cfb;static const ALG_ID seed_ofb;static const ALG_ID seed_cbc;static const ALG_ID rc2_ecb;static con St alg_id rc2_cfb;static Const ALG_ID Rc2_ofb;statIC Const ALG_ID rc2_cbc;static const ALG_ID rc2_40_cbc;static const ALG_ID rc2_64_cbc;static const ALG_ID bf_ecb;static Co NST alg_id bf_cfb;static const alg_id bf_ofb;static const ALG_ID bf_cbc;static const ALG_ID cast5_ecb;static const ALG_ID cast5_cfb;static Const ALG_ID cast5_ofb;static const ALG_ID cast5_cbc;static const ALG_ID rc5_32_12_16_ecb;static const A lg_id rc5_32_12_16_cfb;static const ALG_ID rc5_32_12_16_ofb;static const ALG_ID rc5_32_12_16_cbc;static const ALG_ID AES _128_ecb;static Const ALG_ID aes_128_cbc;static const ALG_ID aes_128_cfb;static const ALG_ID aes_128_cfb1;static const AL g_id aes_128_cfb8;static const ALG_ID aes_128_ofb;static const ALG_ID aes_128_ctr;static const ALG_ID aes_128_gcm;static Const ALG_ID aes_128_xts;static const ALG_ID aes_192_ecb;static const ALG_ID aes_192_cbc;static const ALG_ID AES_192_CFB; static const alg_id Aes_192_cfb1;static const ALG_ID aes_192_cfb8;static const ALG_ID aes_192_ofb;static const ALG_ID Aes_ 192_ctr;static Const ALG_ID AEs_192_gcm;static Const ALG_ID aes_256_ecb;static const ALG_ID aes_256_cbc;static const ALG_ID aes_256_cfb;static const AL g_id aes_256_cfb1;static const ALG_ID aes_256_cfb8;static const ALG_ID aes_256_ofb;static const ALG_ID aes_256_ctr; static const alg_id Aes_256_gcm;static const ALG_ID aes_256_xts;static const ALG_ID CAMELLIA_128_ECB; static const ALG_ID CAMELLIA_128_CBC, static const ALG_ID CAMELLIA_128_CFB, static const alg_id camellia_128_cfb1;static const ALG_ID Camelli a_128_cfb8;static const ALG_ID CAMELLIA_128_OFB; static const alg_id CAMELLIA_192_ECB; static const ALG_ID Camellia_192_c BC; static const alg_id CAMELLIA_192_CFB; static const alg_id camellia_192_cfb1;static const ALG_ID Camellia_192_cfb8;sta Tic const alg_id CAMELLIA_192_OFB; static const alg_id CAMELLIA_256_ECB; static const alg_id CAMELLIA_256_CBC; static cons t alg_id camellia_256_cfb; static const alg_id camellia_256_cfb1;static const ALG_ID camellia_256_cfb8;static const ALG_I D CAMELLIA_256_OFB;}; Public:ciphercALC (); ~ciphercalc (void);//@param ALG Algorithm identification//@param key key//@param IV CBC algorithm initial vector, if iv==null, then the IV value is full 0. @param enc encrypt represents cryptographic operations, decrypt means that decryption operations//@param padding data is populated by default for the user to populate, that is, Ciphercalc does not make any corrections to the input data. @return Error returned false, successfully returned Truebool Init (alg_id alg,unsigned char *key,const unsigned char *iv, Encmode enc, padmode padding = padmode::no_padding);//@param in input buffer address//@param INL input data length//@param out output buffer address//@param outl return *outl+ output data length//@return Out Error returned false, successfully returned Truebool Update (const unsigned char *in,int inl,unsigned char *out,int *outl);//@param out output buffer address//@param o UTL return *outl+ output data length//@return error returned false, successfully returned Truebool Final (unsigned char *out,int *outl);p Rivate:_ciphercalc *_impl; Ciphercalc (const CIPHERCALC &); Ciphercalc &operator= (const CIPHERCALC &);}; #endif

  

C + + interface of the openssl+ algorithm in its own package

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.