Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Official document of <a href="http://www.cryptopp.com/wiki/Advanced_Encryption_Standard" rel="noreferrer">Crypto++ AES</a> is a good start. And from my archive, a basic implementation of AES is as follows:</p> <p>Please refer <a href="http://www.cryptopp.com/fom-serve/cache/79.html" rel="noreferrer">here</a> with more explanation, I recommend you first understand the <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard" rel="noreferrer">algorithm</a> and then try to understand each line step by step.</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; #include "modes.h" #include "aes.h" #include "filters.h" int main(int argc, char* argv[]) { //Key and IV setup //AES encryption uses a secret key of a variable length (128-bit, 196-bit or 256- //bit). This key is secretly exchanged between two parties before communication //begins. DEFAULT_KEYLENGTH= 16 bytes byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ]; memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH ); memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE ); // // String and Sink setup // std::string plaintext = "Now is the time for all good men to come to the aide..."; std::string ciphertext; std::string decryptedtext; // // Dump Plain Text // std::cout &lt;&lt; "Plain Text (" &lt;&lt; plaintext.size() &lt;&lt; " bytes)" &lt;&lt; std::endl; std::cout &lt;&lt; plaintext; std::cout &lt;&lt; std::endl &lt;&lt; std::endl; // // Create Cipher Text // CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, iv ); CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext ) ); stfEncryptor.Put( reinterpret_cast&lt;const unsigned char*&gt;( plaintext.c_str() ), plaintext.length() + 1 ); stfEncryptor.MessageEnd(); // // Dump Cipher Text // std::cout &lt;&lt; "Cipher Text (" &lt;&lt; ciphertext.size() &lt;&lt; " bytes)" &lt;&lt; std::endl; for( int i = 0; i &lt; ciphertext.size(); i++ ) { std::cout &lt;&lt; "0x" &lt;&lt; std::hex &lt;&lt; (0xFF &amp; static_cast&lt;byte&gt;(ciphertext[i])) &lt;&lt; " "; } std::cout &lt;&lt; std::endl &lt;&lt; std::endl; // // Decrypt // CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv ); CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink( decryptedtext ) ); stfDecryptor.Put( reinterpret_cast&lt;const unsigned char*&gt;( ciphertext.c_str() ), ciphertext.size() ); stfDecryptor.MessageEnd(); // // Dump Decrypted Text // std::cout &lt;&lt; "Decrypted Text: " &lt;&lt; std::endl; std::cout &lt;&lt; decryptedtext; std::cout &lt;&lt; std::endl &lt;&lt; std::endl; return 0; } </code></pre> <p>For installation details :</p> <ul> <li><a href="https://stackoverflow.com/questions/6619042/how-do-i-install-crypto-in-visual-studio-2010-windows-7">How do I install Crypto++ in Visual Studio 2010 Windows 7?</a></li> <li><a href="http://www.cryptopp.com/wiki/Linux" rel="noreferrer">*nix environment</a></li> <li>For Ubuntu I did: </li> </ul> <p><code>sudo apt-get install libcrypto++-dev libcrypto++-doc libcrypto++-utils</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload