SHARE
TWEET

AES en/decryption

Sprenger120 Jul 31st, 2012 863 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* *AES en/decryption */
  2. /* *Using Crypto++ */
  3. #include <iostream>
  4. #include <osrng.h>
  5. #include <rsa.h>
  6. #include <files.h>
  7. #include <sstream>
  8. #include <modes.h>
  9. #include <aes.h>
  10. #include <cstring>
  11. using namespace CryptoPP;
  12. using std::stringstream;
  13.  
  14. /* sDecryptedSharedSecret  was taken from http://pastebin.com/7Jvaama1 */
  15.  
  16. /* Initial Vector */
  17. byte IV[AES::BLOCKSIZE];
  18. memcpy(IV,sDecryptedSharedSecret.c_str(),16);
  19.  
  20. /* De/Encryptor */
  21. CFB_Mode<AES>::Decryption AESDecryptor((byte*)sDecryptedSharedSecret.c_str(),(unsigned int)16,IV,1);
  22. CFB_Mode<AES>::Encryption AESEncryptor((byte*)sDecryptedSharedSecret.c_str(),(unsigned int)16,IV,1);
  23.  
  24. /* Encrypt Data */
  25. string sSource("Fill me with data");
  26. string sTarget("");
  27.  
  28. try {
  29. StringSource(sSource, true,
  30.              new StreamTransformationFilter(AESEncryptor,
  31.                                            new StringSink(sTarget)
  32.                                            )
  33.             );
  34. } catch (CryptoPP::Exception) {
  35. std::cout<<"Something went wrong\n";
  36. }
  37.  
  38.  
  39. /* Decrypt data */
  40. //same as above, just set AESEncryptor to AESDecryptor
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top