AES with padding pkcs7 c++ code

后端 未结 2 1062
南笙
南笙 2021-01-07 03:59

I need an example of string encryption (in C++ -> I\'m working on linux-Ubuntu) with aes-cbc256 and a padding: PKCS7 Please help.


For the following code how ca

2条回答
  •  盖世英雄少女心
    2021-01-07 04:34

    look also at my answer to this question

    I suggest checking out cryptopp. Here's a code sample:

    CryptoPP::CBC_Mode::Encryption encryptor;
    byte* key;
    size_t keylen;
    // ... acquire key
    
    encryptor.SetKey( key, keylen );
    
    std::string input;
    std::string result;
    // read input ...
    
    StringSource( input, true,
           new StreamTransformationFilter( encryptor, new StringSink( result ),
         StreamTransformationFilter::PKCS_PADDING));
    

    The values for padding mode in StreamTransformationFilter can be:

    BlockPaddingScheme { 
      NO_PADDING, ZEROS_PADDING, PKCS_PADDING, ONE_AND_ZEROS_PADDING, 
      DEFAULT_PADDING 
    }
    

    EDIT: replaced the padding mode in the sample to pkcs

提交回复
热议问题