Example #1
0
string ookAESCipher::Decrypt(string msg)
{	
	// Recovered Text Sink
	std::string RecoveredText;
	
	// Decryptor
	CryptoPP::CFB_Mode< CryptoPP::AES >::Decryption Decryptor( _keybytes, CryptoPP::AES::DEFAULT_KEYLENGTH );
	
	// Decryption
	CryptoPP::StringSource( msg, true,
												 new CryptoPP::StreamTransformationFilter( Decryptor,
																																	new CryptoPP::StringSink( RecoveredText )
																																	) // StreamTransformationFilter
												 ); // StringSource		

	return RecoveredText;
}
Example #2
0
string ookBlowfishCipher::Decrypt(string msg)
{
	// Recovered Text Sink
	std::string RecoveredText;
	
	// Decryptor
	CryptoPP::CFB_Mode< CryptoPP::Blowfish >::Decryption Decryptor( _keybytes, CryptoPP::Blowfish::DEFAULT_KEYLENGTH );
	
	// Decryption
	CryptoPP::StringSource( msg, true,
												 new CryptoPP::StreamTransformationFilter( Decryptor,
																																	new CryptoPP::StringSink( RecoveredText )
																																	) // StreamTransformationFilter
												 ); // StringSource		
	
	return RecoveredText;	
	
/*	
	ucstring rRet;

	for(int i = 0; i < msg.size(); i += _BLOCK_SIZE)
	{
		vector<uchar> vchunk;
		vector<uchar> rchunk;

		//Pull a block size chunk off of our input vector
		for(int j=i; (j - i) < _BLOCK_SIZE; j++)
			vchunk.push_back(msg[j]);

		//Decrypt the chunk
		rchunk = Decode(vchunk);

		//Push the results onto our return vector
		for(int k=0; k < _BLOCK_SIZE; k++)
			rRet += rchunk[k];
	}

	return rRet;
*/
	
//	return "";
}
Example #3
0
int main(int argc, char* argv[]) {

   try
   {
      // Key and IV setup
      byte key[ CryptoPP::CIPHER::DEFAULT_KEYLENGTH ],
            iv[ CryptoPP::CIPHER::BLOCKSIZE ];

      ::memset( key, 0x01, CryptoPP::CIPHER::DEFAULT_KEYLENGTH );
      ::memset( iv, 0x01, CryptoPP::CIPHER::BLOCKSIZE );

      // Message M
      std::string PlainText = "Yoda said, Do or Do Not. There is no try.";

      // Cipher Text Sink
      std::string CipherText;

      // Encryptor
      CryptoPP::CIPHER_MODE<CryptoPP::CIPHER>::Encryption
         Encryptor( key, sizeof(key), iv );

      // Encryption
      CryptoPP::StringSource( PlainText, true,
         new CryptoPP::StreamTransformationFilter( Encryptor,
            new CryptoPP::StringSink( CipherText )
         ) // StreamTransformationFilter
      ); // StringSource

      ///////////////////////////////////////
      // DMZ //
      ///////////////////////////////////////

      // Recovered Text Sink
      std::string RecoveredText;

      // Decryptor
      CryptoPP::CIPHER_MODE<CryptoPP::CIPHER>::Decryption
         Decryptor( key, sizeof(key), iv );

      // Decryption
      CryptoPP::StringSource( CipherText, true,
         new CryptoPP::StreamTransformationFilter( Decryptor,
            new CryptoPP::StringSink( RecoveredText )
         ) // StreamTransformationFilter
      ); // StringSource

      //////////////////////////////////////////
      // Output //
      //////////////////////////////////////////

      std::cout << "Algorithm:" << std::endl;
      std::cout << " " << Encryptor.AlgorithmName() << std::endl;
      std::cout << "Minimum Key Size:" << std::endl;
      std::cout << " " << Encryptor.MinKeyLength() << " bytes" << std::endl;
      std::cout << std::endl;

      std::cout << "Plain Text (" << PlainText.length() << " bytes)" << std::endl;
      std::cout << " '" << PlainText << "'" << std::endl;
      std::cout << std::endl;

      std::cout << "Cipher Text Size:" << std::endl;
      std::cout << " " << CipherText.size() << " bytes" << std::endl;
      std::cout << std::endl;

      std::cout << "Cipher Text :" << std::endl;
      std::cout << "[" << CipherText << "]" << std::endl;
      std::cout << std::endl;

      std::cout << "Recovered Text:" << std::endl;
      std::cout << " '" << RecoveredText << "'" << std::endl;
      std::cout << std::endl;
   }
   catch( CryptoPP::Exception& e)
   {
      std::cerr << e.what() << std::endl;
   }
   
   catch(...)
   {
      std::cerr << "Unknown Error" << std::endl;
   }   

   return 0;
}