📄 aes.cpp
字号:
// AES.cpp : Implementation of CAES
#include "stdafx.h"
#include "AES_ATL.h"
#include "AES.h"
#include "files.h"
#include "AESPHM.h"
#include "osrng.h"
#include <COMDEF.H>
using namespace std;
using namespace CryptoPP;
/////////////////////////////////////////////////////////////////////////////
// CAES
STDMETHODIMP CAES::Encrypt(BSTR FileName_In, BSTR FileName_Key, BSTR *FileName_Out)
{
// TODO: Add your implementation code here
_bstr_t a = FileName_In;
_bstr_t b = FileName_Key;
_bstr_t c = * FileName_Out;
char * lpFin = a;
char * lpk = b;
char * lpFout= c;
AutoSeededRandomPool rng;
string sPlaintext;
string sKey;
FileSource(lpFin, true,new StringSink(sPlaintext));
FileSource(lpk, true,new StringSink(sKey));
SecByteBlock Ciphertext(NULL,(sPlaintext.size()/15)*15+46);
AESPHM::Encrypt(rng, sKey, Ciphertext, sPlaintext);
FileSink(lpFout).Put(Ciphertext.begin(),Ciphertext.size());
return S_OK;
}
STDMETHODIMP CAES::Decrypt(BSTR FileName_In, BSTR FileName_Key, BSTR *FileName_Out)
{
// TODO: Add your implementation code here
_bstr_t a = FileName_In;
_bstr_t b = FileName_Key;
_bstr_t c = * FileName_Out;
char * lpFin = a;
char * lpk = b;
char * lpFout= c;
string sCiphertext;
string sKey;
FileSource(lpFin, true,new StringSink(sCiphertext));
FileSource(lpk, true,new StringSink(sKey));
SecByteBlock Plaintext(sCiphertext.size()-31);
int length = AESPHM::Decrypt(sKey, Plaintext,sCiphertext ).messageLength;
FileSink(lpFout).Put(Plaintext.begin(), length);
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -