Ejemplo n.º 1
0
string ookBlowfishCipher::Encrypt(string msg)
{
	// Cipher Text Sink
	std::string CipherText;
	
	// Encryptor
	CryptoPP::CFB_Mode< CryptoPP::Blowfish >::Encryption Encryptor(_keybytes, CryptoPP::Blowfish::DEFAULT_KEYLENGTH);	
	
	// Encryption
	CryptoPP::StringSource(msg, true,
												 new CryptoPP::StreamTransformationFilter( Encryptor,
																																	new CryptoPP::StringSink( CipherText )
																																	) // StreamTransformationFilter
												 ); // StringSource
	
	return CipherText;	
/*	
	vector<uchar> rRet;
	for(int i = 0; i < msg.length(); i += _BLOCK_SIZE)
	{
		vector<uchar> vchunk;
		vector<uchar> rchunk;

		//Fetch a block size chunk off the message string
		ucstring chunk = msg.substr(i, _BLOCK_SIZE);

		//Push message chunk characters onto our vector
		for(int j=0; j < chunk.length(); j++)
			vchunk.push_back(chunk[j]);

		//null pad any short chunks. Should only be the last one
		for(int l = vchunk.size(); l < _BLOCK_SIZE; l++)
			vchunk.push_back('\0');

		//Encode the chunk
		rchunk = Encode(vchunk);

		//Push the encrypted text onto our return vector
		for(int k=0; k < _BLOCK_SIZE; k++)
			rRet.push_back(rchunk[k]);
	}
		
	return rRet;
*/
	
//	return "";
}
Ejemplo n.º 2
0
string ookAESCipher::Encrypt(string msg)
{	
	// Cipher Text Sink
	std::string CipherText;
		
	// Encryptor
	CryptoPP::CFB_Mode< CryptoPP::AES >::Encryption Encryptor(_keybytes, CryptoPP::AES::DEFAULT_KEYLENGTH);	
	
	// Encryption
	CryptoPP::StringSource(msg, true,
												 new CryptoPP::StreamTransformationFilter( Encryptor,
																																	new CryptoPP::StringSink( CipherText )
																																	) // StreamTransformationFilter
												 ); // StringSource
	
	return CipherText;
}
Ejemplo n.º 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;
}