亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? test.cpp

?? 此文件是實(shí)現(xiàn)加解密算法的函數(shù)庫
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// test.cpp - written and placed in the public domain by Wei Dai

#include "pch.h"
#include "md5.h"
#include "sha.h"
#include "ripemd.h"
#include "files.h"
#include "rng.h"
#include "hex.h"
#include "gzip.h"
#include "default.h"
#include "rsa.h"
#include "randpool.h"
#include "ida.h"
#include "base64.h"
#include "socketft.h"
#include "dsa.h"
#include "rsa.h"
#include "osrng.h"
#include "wait.h"
#include "fips140.h"

#include "validate.h"
#include "bench.h"

#include <iostream>
#include <time.h>

#if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
#endif

#if (_MSC_VER >= 1000)
#include <crtdbg.h>		// for the debug heap
#endif

#if defined(__MWERKS__) && defined(macintosh)
#include <console.h>
#endif

USING_NAMESPACE(CryptoPP)
USING_NAMESPACE(std)

const int MAX_PHRASE_LENGTH=250;

void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
string RSAEncryptString(const char *pubFilename, const char *seed, const char *message);
string RSADecryptString(const char *privFilename, const char *ciphertext);
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename);
bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename);

void DigestFile(const char *file);

string EncryptString(const char *plaintext, const char *passPhrase);
string DecryptString(const char *ciphertext, const char *passPhrase);

void EncryptFile(const char *in, const char *out, const char *passPhrase);
void DecryptFile(const char *in, const char *out, const char *passPhrase);

void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed);
void SecretRecoverFile(int threshold, const char *outFilename, char *const *inFilenames);

void InformationDisperseFile(int threshold, int nShares, const char *filename);
void InformationRecoverFile(int threshold, const char *outFilename, char *const *inFilenames);

void GzipFile(const char *in, const char *out, int deflate_level);
void GunzipFile(const char *in, const char *out);

void Base64Encode(const char *in, const char *out);
void Base64Decode(const char *in, const char *out);
void HexEncode(const char *in, const char *out);
void HexDecode(const char *in, const char *out);

void ForwardTcpPort(const char *sourcePort, const char *destinationHost, const char *destinationPort);

void FIPS140_SampleApplication(const char *moduleFilename, const char *edcFilename);
void FIPS140_GenerateRandomFiles();

bool Validate(int, bool, const char *);

#ifdef __BCPLUSPLUS__
int cmain(int argc, char *argv[])
#elif defined(_MSC_VER)
int __cdecl main(int argc, char *argv[])
#else
int main(int argc, char *argv[])
#endif
{
#ifdef _CRTDBG_LEAK_CHECK_DF
	// Turn on leak-checking
	int tempflag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
	tempflag |= _CRTDBG_LEAK_CHECK_DF;
	_CrtSetDbgFlag( tempflag );
#endif

#if defined(__MWERKS__) && defined(macintosh)
	argc = ccommand(&argv);
#endif

	try
	{
		std::string command, executableName, edcFilename;

		if (argc < 2)
			command = 'h';
		else
			command = argv[1];

		if (FIPS_140_2_ComplianceEnabled())
		{
			edcFilename = "edc.dat";

#if defined(_WIN32) || defined(__CYGWIN__)
			TCHAR filename[MAX_PATH];
			GetModuleFileName(GetModuleHandle(NULL), filename, sizeof(filename));
			executableName = filename;
			std::string::size_type pos = executableName.rfind('\\');
			if (pos != std::string::npos)
				edcFilename = executableName.substr(0, pos+1) + edcFilename;
#else
			executableName = argv[0];
#endif

			if (command.substr(0, 4) != "fips")
			{
				byte expectedModuleDigest[SHA1::DIGESTSIZE];
				FileSource(edcFilename.c_str(), true, new HexDecoder(new ArraySink(expectedModuleDigest, sizeof(expectedModuleDigest))));

				DoPowerUpSelfTest(executableName.c_str(), expectedModuleDigest);
			}
		}

		switch (command[0])
		{
		case 'g':
		  {
			char seed[1024], privFilename[128], pubFilename[128];
			unsigned int keyLength;

			cout << "Key length in bits: ";
			cin >> keyLength;

			cout << "\nSave private key to file: ";
			cin >> privFilename;

			cout << "\nSave public key to file: ";
			cin >> pubFilename;

			cout << "\nRandom Seed: ";
			ws(cin);
			cin.getline(seed, 1024);

			GenerateRSAKey(keyLength, privFilename, pubFilename, seed);
			return 0;
		  }
		case 'r':
		  {
			switch (argv[1][1])
			{
			case 's':
				RSASignFile(argv[2], argv[3], argv[4]);
				return 0;
			case 'v':
			  {
				bool verified = RSAVerifyFile(argv[2], argv[3], argv[4]);
				cout << (verified ? "valid signature" : "invalid signature") << endl;
				return 0;
			  }
			default:
			  {
				char privFilename[128], pubFilename[128];
				char seed[1024], message[1024];

				cout << "Private key file: ";
				cin >> privFilename;

				cout << "\nPublic key file: ";
				cin >> pubFilename;

				cout << "\nRandom Seed: ";
				ws(cin);
				cin.getline(seed, 1024);

				cout << "\nMessage: ";
				cin.getline(message, 1024);

				string ciphertext = RSAEncryptString(pubFilename, seed, message);
				cout << "\nCiphertext: " << ciphertext << endl;

				string decrypted = RSADecryptString(privFilename, ciphertext.c_str());
				cout << "\nDecrypted: " << decrypted << endl;

				return 0;
			  }
			}
		  }
		case 'm':
			DigestFile(argv[2]);
			return 0;
		case 't':
		  {
			// VC60 workaround: use char array instead of std::string to workaround MSVC's getline bug
			char passPhrase[MAX_PHRASE_LENGTH], plaintext[1024];

			cout << "Passphrase: ";
			cin.getline(passPhrase, MAX_PHRASE_LENGTH);

			cout << "\nPlaintext: ";
			cin.getline(plaintext, 1024);

			string ciphertext = EncryptString(plaintext, passPhrase);
			cout << "\nCiphertext: " << ciphertext << endl;

			string decrypted = DecryptString(ciphertext.c_str(), passPhrase);
			cout << "\nDecrypted: " << decrypted << endl;

			return 0;
		  }
		case 'e':
		case 'd':
			if (command == "e64")
				Base64Encode(argv[2], argv[3]);
			else if (command == "d64")
				Base64Decode(argv[2], argv[3]);
			else if (command == "e16")
				HexEncode(argv[2], argv[3]);
			else if (command == "d16")
				HexDecode(argv[2], argv[3]);
			else
			{
				char passPhrase[MAX_PHRASE_LENGTH];
				cout << "Passphrase: ";
				cin.getline(passPhrase, MAX_PHRASE_LENGTH);
				if (command == "e")
					EncryptFile(argv[2], argv[3], passPhrase);
				else
					DecryptFile(argv[2], argv[3], passPhrase);
			}
			return 0;
		case 's':
			if (argv[1][1] == 's')
			{
				char seed[1024];
				cout << "\nRandom Seed: ";
				ws(cin);
				cin.getline(seed, 1024);
				SecretShareFile(atoi(argv[2]), atoi(argv[3]), argv[4], seed);
			}
			else
				SecretRecoverFile(argc-3, argv[2], argv+3);
			return 0;
		case 'i':
			if (argv[1][1] == 'd')
				InformationDisperseFile(atoi(argv[2]), atoi(argv[3]), argv[4]);
			else
				InformationRecoverFile(argc-3, argv[2], argv+3);
			return 0;
		case 'v':
			return !Validate(argc>2 ? atoi(argv[2]) : 0, argv[1][1] == 'v', argc>3 ? argv[3] : NULL);
		case 'b':
			if (argc<3)
				BenchMarkAll();
			else
				BenchMarkAll((float)atof(argv[2]));
			return 0;
		case 'z':
			GzipFile(argv[3], argv[4], argv[2][0]-'0');
			return 0;
		case 'u':
			GunzipFile(argv[2], argv[3]);
			return 0;
		case 'f':
			if (command == "fips")
				FIPS140_SampleApplication(executableName.c_str(), edcFilename.c_str());
			else if (command == "fips-rand")
				FIPS140_GenerateRandomFiles();
			else if (command == "ft")
				ForwardTcpPort(argv[2], argv[3], argv[4]);
			return 0;
		default:
			FileSource usage("usage.dat", true, new FileSink(cout));
			return 1;
		}
	}
	catch(CryptoPP::Exception &e)
	{
		cout << "\nCryptoPP::Exception caught: " << e.what() << endl;
		return -1;
	}
	catch(std::exception &e)
	{
		cout << "\nstd::exception caught: " << e.what() << endl;
		return -2;
	}
}

void FIPS140_SampleApplication(const char *moduleFilename, const char *edcFilename)
{
	if (!FIPS_140_2_ComplianceEnabled())
	{
		cerr << "FIPS-140-2 compliance was turned off at compile time.\n";
		abort();
	}

	// try to use a crypto algorithm before doing a self test
	try
	{
		// trying to use a crypto algorithm before power-up self test will result in an exception
		DES::Encryption des;

		// should not be here
		cerr << "Use of DES before power-up test failed to cause an exception.\n";
		abort();
	}
	catch (SelfTestFailure &e)
	{
		cout << "0. Caught expected exception. Exception message follows: ";
		cout << e.what() << endl;
	}

	// simulate a power-up self test error
	SimulatePowerUpSelfTestFailure();
	try
	{
		// trying to use a crypto algorithm after power-up self test error will result in an exception
		DES::Encryption des;

		// should not be here
		cerr << "Use of DES failed to cause an exception after power-up self test error.\n";
		abort();
	}
	catch (SelfTestFailure &e)
	{
		cout << "1. Caught expected exception when simulating self test failure. Exception message follows: ";
		cout << e.what() << endl;
	}

	// clear the self test error state and do power-up self test
	byte expectedModuleDigest[SHA1::DIGESTSIZE];
	FileSource(edcFilename, true, new HexDecoder(new ArraySink(expectedModuleDigest, sizeof(expectedModuleDigest))));

	DoPowerUpSelfTest(moduleFilename, expectedModuleDigest);
	if (GetPowerUpSelfTestStatus() != POWER_UP_SELF_TEST_PASSED)
	{
		cerr << "Power-up self test failed.\n";
		abort();
	}
	cout << "2. Power-up self test passed.\n";

	// encrypt and decrypt
	const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
	const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
	const byte plaintext[] = {	// "Now is the time for all " without tailing 0
		0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
		0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
		0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};
	byte ciphertext[24];
	byte decrypted[24];

	CFB_Mode<DES>::Encryption encryption_DES_CBC;
	encryption_DES_CBC.SetKeyWithIV(key, 8, iv);
	encryption_DES_CBC.ProcessString(ciphertext, plaintext, 24);

	CFB_Mode<DES>::Decryption decryption_DES_CBC;
	decryption_DES_CBC.SetKeyWithIV(key, 8, iv);
	decryption_DES_CBC.ProcessString(decrypted, ciphertext, 24);

	if (memcmp(plaintext, decrypted, 24) != 0)
	{
		cerr << "DES-CBC Encryption/decryption failed.\n";
		abort();
	}
	cout << "3. DES-CBC Encryption/decryption succeeded.\n";

	// hash
	const byte message[] = {'a', 'b', 'c'};
	const byte expectedDigest[] = {0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D};
	byte digest[20];
	
	SHA1 sha;
	sha.Update(message, 3);
	sha.Final(digest);

	if (memcmp(digest, expectedDigest, 20) != 0)
	{
		cerr << "SHA-1 hash failed.\n";
		abort();
	}
	cout << "4. SHA-1 hash succeeded.\n";

	// create auto-seeded X9.17 RNG object, if available
#ifdef OS_RNG_AVAILABLE
	AutoSeededX917RNG<DES_EDE3> rng;
#else
	// this is used to allow this function to compile on platforms that don't have auto-seeded RNGs
	RandomNumberGenerator &rng(NullRNG());
#endif

	// generate DSA key
	DSA::PrivateKey dsaPrivateKey;
	dsaPrivateKey.GenerateRandomWithKeySize(rng, 1024);
	DSA::PublicKey dsaPublicKey;
	dsaPublicKey.AssignFrom(dsaPrivateKey);
	if (!dsaPrivateKey.Validate(rng, 3) || !dsaPublicKey.Validate(rng, 3))
	{
		cerr << "DSA key generation failed.\n";
		abort();
	}
	cout << "5. DSA key generation succeeded.\n";

	// encode DSA key
	std::string encodedDsaPublicKey, encodedDsaPrivateKey;
	dsaPublicKey.DEREncode(StringSink(encodedDsaPublicKey).Ref());
	dsaPrivateKey.DEREncode(StringSink(encodedDsaPrivateKey).Ref());

	// decode DSA key
	DSA::PrivateKey decodedDsaPrivateKey;
	decodedDsaPrivateKey.BERDecode(StringStore(encodedDsaPrivateKey).Ref());
	DSA::PublicKey decodedDsaPublicKey;
	decodedDsaPublicKey.BERDecode(StringStore(encodedDsaPublicKey).Ref());

	if (!decodedDsaPrivateKey.Validate(rng, 3) || !decodedDsaPublicKey.Validate(rng, 3))
	{
		cerr << "DSA key encode/decode failed.\n";
		abort();
	}
	cout << "6. DSA key encode/decode succeeded.\n";

	// sign and verify
	byte signature[40];
	DSA::Signer signer(dsaPrivateKey);
	assert(signer.SignatureLength() == 40);
	signer.SignMessage(rng, message, 3, signature);

	DSA::Verifier verifier(dsaPublicKey);
	if (!verifier.VerifyMessage(message, 3, signature))
	{
		cerr << "DSA signature and verification failed.\n";
		abort();
	}
	cout << "7. DSA signature and verification succeeded.\n";


	// try to verify an invalid signature
	signature[0] ^= 1;
	if (verifier.VerifyMessage(message, 3, signature))
	{
		cerr << "DSA signature verification failed to detect bad signature.\n";
		abort();
	}
	cout << "8. DSA signature verification successfully detected bad signature.\n";

	// try to use an invalid key length
	try
	{
		encryption_DES_CBC.SetKey(key, 5);

		// should not be here
		cerr << "DES implementation did not detect use of invalid key length.\n";

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国产自在久精品国产| 欧洲一区二区三区在线| 一区二区视频免费在线观看| 欧美一级二级三级蜜桃| 成人动漫精品一区二区| 婷婷国产在线综合| 国产精品国产三级国产aⅴ入口 | 亚洲电影一区二区| 国产欧美日韩在线视频| 在线电影一区二区三区| 91麻豆福利精品推荐| 国产精品一二三区在线| 视频精品一区二区| 伊人色综合久久天天人手人婷| 2020国产精品| 日韩一区二区精品葵司在线| 在线观看国产精品网站| 成人av小说网| 国产精品91xxx| 精品一区二区三区在线播放| 亚洲va在线va天堂| 亚洲免费观看视频| 国产精品日韩成人| 久久久久久免费| 日韩一级免费一区| 欧美高清视频一二三区 | 91福利社在线观看| 国产99久久久国产精品| 看片的网站亚洲| 视频一区二区中文字幕| 亚洲国产wwwccc36天堂| 亚洲欧美另类久久久精品| 国产精品三级av在线播放| 久久久综合精品| 日韩精品一区在线| 欧美一级黄色片| 884aa四虎影成人精品一区| 欧美三级视频在线观看| 日本韩国精品在线| 色诱亚洲精品久久久久久| av资源网一区| 午夜视频一区在线观看| 午夜视频在线观看一区二区| 欧美午夜一区二区| 一本色道a无线码一区v| 国产欧美综合在线| 久久久99精品久久| 久久综合色天天久久综合图片| 91精品国产全国免费观看| 在线成人av网站| 91精品国产色综合久久久蜜香臀| 欧美日韩国产综合视频在线观看| 欧美日韩在线三区| 91精品国产一区二区三区香蕉| 欧美一级片在线看| 久久蜜桃av一区二区天堂| 国产精品理伦片| 亚洲日韩欧美一区二区在线| 一区二区国产视频| 丝袜美腿亚洲综合| 久久国产欧美日韩精品| 国产精品一区二区91| 成人一级视频在线观看| 99国产精品久久久久| 色狠狠桃花综合| 欧美精品xxxxbbbb| 精品久久人人做人人爰| 欧美韩日一区二区三区四区| 亚洲美女屁股眼交3| 天天av天天翘天天综合网色鬼国产| 奇米色一区二区| 国产乱码一区二区三区| 91免费在线视频观看| 欧美精品黑人性xxxx| 久久久久99精品国产片| 亚洲青青青在线视频| 亚洲国产综合91精品麻豆| 久久精品99久久久| av在线不卡观看免费观看| 欧美性xxxxxx少妇| 欧美精品一区男女天堂| 亚洲视频香蕉人妖| 日本不卡不码高清免费观看| 成人精品视频一区二区三区尤物| 欧美少妇性性性| 久久久午夜精品| 一区二区理论电影在线观看| 黄色日韩网站视频| 色老汉一区二区三区| 精品福利在线导航| 亚洲激情欧美激情| 国产一区二区免费在线| 在线视频一区二区免费| 久久精品一区二区| 亚洲成人免费影院| 成人av手机在线观看| 欧美一区二区精品在线| 中文字幕综合网| 久久99精品久久只有精品| 在线观看亚洲精品视频| 久久无码av三级| 亚洲电影一级片| 成人高清视频免费观看| 欧美大片一区二区| 亚洲综合免费观看高清完整版在线| 狠狠久久亚洲欧美| 欧美三级电影精品| 国产精品婷婷午夜在线观看| 日韩电影免费在线| 亚洲欧洲一区二区三区| 美女视频网站久久| 91免费版在线| 欧美国产精品v| 国产在线视频一区二区三区| 4438x成人网最大色成网站| 亚洲美女淫视频| 国产不卡在线视频| 亚洲精品一区在线观看| 日av在线不卡| 欧美体内she精高潮| 亚洲色图都市小说| 成人性生交大片免费看中文网站| 日韩你懂的在线观看| 性感美女极品91精品| 91国产丝袜在线播放| 综合激情网...| 成人精品国产免费网站| 久久精品视频一区二区三区| 蜜臀av性久久久久av蜜臀妖精| 在线视频观看一区| 亚洲女人小视频在线观看| 成人福利视频在线看| 欧美国产精品v| 高清成人在线观看| 久久精品亚洲国产奇米99| 国产中文字幕精品| 久久久久综合网| 国产一区二区三区在线观看免费视频| 日韩美女视频在线| 青青青爽久久午夜综合久久午夜| 欧美日韩日日骚| 亚洲国产精品一区二区www| 欧美性猛片xxxx免费看久爱| 一区二区三区精品| 欧洲亚洲精品在线| 亚洲影视资源网| 欧美久久婷婷综合色| 日韩精品一区第一页| 欧美精品xxxxbbbb| 免费观看在线综合| 欧美精品一区二区久久久| 激情文学综合插| 欧美国产日韩在线观看| 91视频精品在这里| 亚洲一区二区黄色| 欧美一级欧美三级在线观看| 久久99这里只有精品| 26uuu国产日韩综合| 国产成人啪午夜精品网站男同| 国产精品久久久久久久久免费相片 | 99视频一区二区| 亚洲免费av高清| 欧美一区二区视频观看视频| 国产一区二区三区四区五区美女| 国产亚洲精品久| 91在线国产福利| 午夜精品久久久| 日本免费新一区视频| 久久久久国产精品免费免费搜索| 成人app下载| 亚洲va欧美va天堂v国产综合| 精品国产免费视频| 91在线一区二区三区| 天堂成人国产精品一区| 久久久亚洲午夜电影| 99r国产精品| 喷白浆一区二区| 国产精品人妖ts系列视频| 欧美日韩另类一区| 国产精品一区2区| 亚洲午夜激情网站| 久久久亚洲高清| 欧美日韩午夜影院| 国产一区二区不卡| 一区二区三区电影在线播| 欧美成人三级电影在线| 色视频一区二区| 国产真实乱对白精彩久久| 亚洲一区二区三区影院| 久久综合999| 欧美日韩一区 二区 三区 久久精品| 黄色资源网久久资源365| 亚洲午夜免费视频| 国产日韩精品一区二区浪潮av| 欧美日韩精品欧美日韩精品 | 麻豆91精品视频| 亚洲少妇中出一区| 久久综合九色综合97婷婷女人| 日本大香伊一区二区三区| 国产一区三区三区|