資源簡介
采用DES的ECB電子密碼本方式進行加密,暫時不支持中文,可自行擴展
代碼片段和文件信息
//?ConsoleApplication1.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?
#include?“randpool.h“
#include?“rsa.h“
#include?“hex.h“
#include?“files.h“
#include?“config.h“
#include?“stdcpp.h“
#include?“modes.h“
#include“base64.h“
using?namespace?std;
using?namespace?CryptoPP;
#pragma?comment(lib?“cryptlib.lib“)
//?加密
string?encrypt(const?std::string&?str_in?const?std::string&?key?const?std::string&?iv)
{
std::string?str_out;
CryptoPP::CFB_Mode::Encryption?encryption((byte*)key.c_str()?key.length()?(byte*)iv.c_str());
CryptoPP::StringSource?encryptor(str_in?true
new?CryptoPP::StreamTransformationFilter(encryption
new?CryptoPP::base64Encoder(
new?CryptoPP::StringSink(str_out)
false?//?do?not?append?a?newline
)
)
);
return?str_out;
}
//解密
//------------------------
string?decrypt(const?std::string&?str_in?const?std::string&?key?const?std::string&?iv)
{
std::string?str_out;
CryptoPP::CFB_Mode::Decryption?decryption((byte*)key.c_str()?key.length()?(byte*)iv.c_str());
CryptoPP::StringSource?decryptor(str_in?true
new?CryptoPP::base64Decoder(
new?CryptoPP::StreamTransformationFilter(decryption
new?CryptoPP::StringSink(str_out)
)
)
);
return?str_out;
}
int?_tmain(int?argc?_TCHAR*?argv[])
{
std::string?str?=?“123456789012345“;??//加密的字符串
std::string?key?=?“01234567891234560123456789123456“;?//?32?bytes
std::string?iv?=?“0123456789123456“;?//?16?bytes
std::string?str_encrypted?=??encrypt(str?key?iv);???//加密后密文
std::string?str_decrypted?=?decrypt(str_encrypted?key?iv);??//解密后明文
std::cout?<“str_encrypted:?“?< std::cout?<“str_decrypted:?“?< int?a;
cin?>>?a;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1871??2018-10-12?09:56??DES2ECB\ConsoleApplication1\ConsoleApplication1.cpp
?????文件???????4922??2018-10-12?09:56??DES2ECB\ConsoleApplication1\ConsoleApplication1.vcxproj
?????文件???????1323??2018-10-12?09:53??DES2ECB\ConsoleApplication1\ConsoleApplication1.vcxproj.filters
?????文件???????1730??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\cl.command.1.tlog
?????文件??????20338??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\CL.read.1.tlog
?????文件???????1036??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\CL.write.1.tlog
?????文件?????????65??2018-10-12?09:56??DES2ECB\ConsoleApplication1\Debug\ConsoleApplication1.lastbuildstate
?????文件??????27555??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\ConsoleApplication1.log
?????文件?????990295??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\ConsoleApplication1.obj
?????文件????1245184??2018-10-12?09:56??DES2ECB\ConsoleApplication1\Debug\ConsoleApplication1.pch
?????文件??????????0??2018-10-12?09:56??DES2ECB\ConsoleApplication1\Debug\ConsoleApplication1.unsuccessfulbuild
?????文件??????????2??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\li
?????文件??????????2??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\li
?????文件??????????2??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\li
?????文件??????????2??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\li
?????文件??????????2??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\li
?????文件??????????2??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\li
?????文件??????????2??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\li
?????文件??????11642??2018-10-12?09:56??DES2ECB\ConsoleApplication1\Debug\stdafx.obj
?????文件?????527360??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\vc110.idb
?????文件????1748992??2018-10-12?09:57??DES2ECB\ConsoleApplication1\Debug\vc110.pdb
?????文件???????1594??2018-10-12?09:53??DES2ECB\ConsoleApplication1\ReadMe.txt
?????文件????????224??2018-10-12?09:53??DES2ECB\ConsoleApplication1\stdafx.cpp
?????文件????????233??2018-10-12?09:53??DES2ECB\ConsoleApplication1\stdafx.h
?????文件????????236??2018-10-12?09:53??DES2ECB\ConsoleApplication1\targetver.h
?????文件??????19456??2018-10-12?09:57??DES2ECB\Debug\ConsoleApplication1.pdb
?????文件????2173978??2018-10-12?09:36??DES2ECB\Debug\cryptopp.lib
?????文件??????75264??2018-10-12?11:04??DES2ECB\Debug\DESEncrypt.dll
?????文件????????778??2018-10-12?10:12??DES2ECB\Debug\DESEncrypt.exp
?????文件?????530672??2018-10-12?11:04??DES2ECB\Debug\DESEncrypt.ilk
............此處省略105個文件信息
評論
共有 條評論