如何运行此AES Crypt程序 [英] How do run this AES Crypt program

查看:67
本文介绍了如何运行此AES Crypt程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#pragma comment (lib,"cryptlib.lib")
#include <cstdio>
#include <cderr.h>
#include <osrng.h>
using CryptoPP::AutoSeededRandomPool;

#include <string>
#include <cstdlib>
#include <cryptlib.h>
using CryptoPP::Exception;

#include <hex.h>
using CryptoPP::HexEncoder;
using CryptoPP::HexDecoder;

#include <filters.h>
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::StreamTransformationFilter;

#include <des.h>
using CryptoPP::DES_EDE2;

#include <modes.h>
using CryptoPP::CBC_Mode;

#include <secblock.h>
using CryptoPP::SecByteBlock;
#include <iostream>
#include <string>
#include <modes.h>
#include <aes.h>
#include <filters.h>
using namespace std;

int main(int argc, char* argv[]) {

	string key = "0123456789abcdef";
	string iv = "aaaaaaaaaaaaaaaa";
	string plain = "CBC Mode Test";
	string cipher, encoded, recovered;


	string plaintext = "mr khakpour plain text example.";
	string ciphertext;
	string decryptedtext;

	cout << "Plain Text (" << plaintext.size() << " bytes)" << endl;
	cout << plaintext;
	cout << endl << endl;

	CryptoPP::AES::Encryption aesEncryption((byte *)key.c_str(), CryptoPP::AES::DEFAULT_KEYLENGTH);
	CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, (byte *)iv.c_str());

	CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink(ciphertext));
	stfEncryptor.Put(reinterpret_cast<const unsigned char*>(plaintext.c_str()), plaintext.length() + 1);
	stfEncryptor.MessageEnd();
	cout << "cipher text plain: " << ciphertext << endl;
	cout << "Cipher Text (" << ciphertext.size() << " bytes)" << endl;
	cout << endl;
	cout << endl;
	cout << "cipher text In HEX FORM:: ";
	for (int i = 0; i < ciphertext.size(); i++) {

		cout << "0x" << hex << (0xFF & static_cast<byte>(ciphertext[i])) << " ";
	}
	cout << endl;
	cout << endl;

	// Pretty print
	encoded.clear();
	StringSource(ciphertext, true,
		new HexEncoder(
		new StringSink(encoded)
		) // HexEncoder
		); // StringSource
	cout << "cipher text In HEX FORM: " << encoded << endl;
	cout << endl;
	cout << endl;
	char *name2;
	name2 = (char*)malloc(encoded.length() + 1); //  free!!!!
	strcpy(name2, encoded.c_str());

	const char* hex_str = name2;

	string result_string;
	unsigned int ch;
	for (; sscanf(hex_str, "%2x", &ch) == 1; hex_str += 2)
		result_string += ch;
	cout << "HEX FORM to cipher text :: ";
	cout << result_string << '\n';
	cout << endl;
	cout << endl;
	/*********************************\
	\*********************************/


	CryptoPP::AES::Decryption aesDecryption((byte *)key.c_str(), CryptoPP::AES::DEFAULT_KEYLENGTH);
	CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, (byte *)iv.c_str());

	CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink(decryptedtext));
	stfDecryptor.Put(reinterpret_cast<const unsigned char*>(result_string.c_str()), result_string.size());
	stfDecryptor.MessageEnd();
	cout << "Decrypted Text: " << endl;
	cout << decryptedtext;
	cout << endl << endl;

	system("pause");

	return 0;
}





i我在dev c ++编译器上编译这个程序但是我遇到错误

请求帮助我在Dev C ++上运行这个程序



i am compile this program on dev c++ compiler but i face error
plese help me to run this program on Dev C++

推荐答案

代码片段用于Visual C ++,但你使用的是Dev C ++。



第一行

The code snippet is for Visual C++ but you are using Dev C++.

The first line
#pragma comment (lib,"cryptlib.lib")



是Microsoft特定并将应用程序与指定的库链接。您必须使用适合您的开发环境的步骤将您的应用程序与该库链接。



但是,您必须确保拥有与您的开发兼容的库版本环境。如有必要,您必须使用Dev C ++构建库。


is Microsoft specific and links the application with the specified library. You must use the appropiate steps for your development environment to link your application with that library.

However, you must ensure to have a library version that is compatible with your development environment. If necessary you must build the library using your Dev C++.


使用dev cpp 5.6.3编译器并添加libcryptopp.a文件以在项目中删除第一行
using dev cpp 5.6.3 compiler and add libcryptopp.a file to project and delete first line in code


这篇关于如何运行此AES Crypt程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆