Unit1.cpp
资源名称:Crypt.zip [点击查看]
上传用户:zhihui0713
上传日期:2022-08-07
资源大小:1k
文件大小:2k
源码类别:
加密解密
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- #include "tripledes.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- PFILEENCRYPT FileEncrypt;
- PFILEDECRYPT FileDecrypt;
- PENCRYPTBUFFER EncryptBuffer;
- PDECRYPTBUFFER DecryptBuffer;
- PFREEBUFFER FreeBuffer;
- HANDLE hLib = ::LoadLibrary("tripledes.dll");
- if(!hLib)
- return;
- FileEncrypt = (PFILEENCRYPT) ::GetProcAddress(hLib,"FileEncrypt");
- FileDecrypt = (PFILEDECRYPT) ::GetProcAddress(hLib,"FileDecrypt");
- EncryptBuffer = (PENCRYPTBUFFER) ::GetProcAddress(hLib,"EncryptBuffer");
- DecryptBuffer = (PDECRYPTBUFFER) ::GetProcAddress(hLib,"DecryptBuffer");
- FreeBuffer = (PFREEBUFFER) ::GetProcAddress(hLib,"FreeBuffer");
- if(!FileEncrypt || !FileDecrypt ||
- !EncryptBuffer || !DecryptBuffer ||
- !FreeBuffer)
- {
- ::FreeLibrary(hLib);
- return;
- }
- // deal with files
- FileEncrypt("C:\test.txt","123456");
- FileDecrypt("C:\test.txt","123456");
- //deal with buffers
- DWORD dwEncSize = Edit1->Text.Length();
- BYTE* encripted = EncryptBuffer(Edit1->Text.c_str(),dwEncSize,"123456",&dwEncSize);
- if(encripted)
- {
- BYTE* decripted = DecryptBuffer(encripted,dwEncSize,"123456");
- if(decripted)
- {
- //::MessageBox(NULL,(char*)decripted,NULL,MB_OK);
- ///Edit2->Text = (char*)decripted;
- Edit2->Text = (char*)encripted;
- FreeBuffer(decripted);
- } // if(decripted)
- FreeBuffer(encripted);
- } // if(encripted)
- ::FreeLibrary(hLib);
- }
- //---------------------------------------------------------------------------