资源简介
利用CryptoAPI进行文件的加解密以及签名和验证服务,文件包括附录ppt
代码片段和文件信息
#include “stdafx.h“
#include
#include
#include
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
#define KEYLENGTH 0x00800000
void HandleError(char *s);
//--------------------------------------------------------------------
// These additional #define statements are required.
#define ENCRYPT_ALGORITHM CALG_RC4
#define ENCRYPT_BLOCK_SIZE 8
#define MAX_FILE_SIZE 4000000
#define SIGNATURE_SIZE 500
BYTE *pbKeyBlob; //用来保存导出的公钥
DWORD dwBlobLen;
// Declare the functions. The function definition
// follows main.
BOOL VerifyFile (
PCHAR szSource
PCHAR szDestination);
BOOL SignFile (
PCHAR szSource
PCHAR szDestination);
BOOL DecryptFile(
PCHAR szSource
PCHAR szDestination
PCHAR szPassword);
BOOL EncryptFile(
PCHAR szSource
PCHAR szDestination
PCHAR szPassword);
//--------------------------------------------------------------------
// Begin main.
int main()
{
CHAR szSource[100];
CHAR szDestination[100];
CHAR szPassword[100];
int Service;
char judge;
bool DoOrNot=true;
do{
printf(“**************************************************************\n“);
printf(“请选择服务开始项:\n“);
printf(“1.加密\t2.解密\n3.签名\t4.验证\n“);
scanf(“%d“&Service);
switch(Service){
case 1:
//--------------------------------------------------------------------
// Call EncryptFile to do the actual encryption. 加密文件
printf(“\n------------------------------------------------------------\n“);
printf(“\n\n1.Encrypt a file. \n\n“);
printf(“\nEnter the name of the file to be encrypted: “);
scanf(“%s“szSource);
printf(“\nEnter the name of the output file: “);
scanf(“%s“szDestination);
printf(“\nEnter the password:“);
scanf(“%s“szPassword);
if(EncryptFile(szSource szDestination szPassword))
{
printf(“\nEncryption of the file %s was a success. \n“ szSource);
printf(“\nThe encrypted data is in file %s.\n“szDestination);
}else{
HandleError(“\nError encrypting file!“);
}
case 2:
//--------------------------------------------------------------------
// Call Decryptfile to do the actual decryption. 解密文件
printf(“\n------------------------------------------------------------\n“);
printf(“\n\n2.Decrypt a file. \n\n“);
printf(“\nEnter the name of the file to be decrypted: “);
scanf(“%s“szSource);
printf(“\nEnter the name of the output file: “);
scanf(“%s“szDestination);
printf(“\nEnter the password:“);
scanf(“%s“szPassword);
if(DecryptFile(szSource szDestination szPassword))
{
printf(“\nDecryption of the file %s was a success. \n“ szSource);
printf(“\nThe decrypted data is in file %s.\n“szDestination);
}else{
HandleError(“\nError decrypting file!“);
}
case 3:
//--------------------------------------------------------------------
// Call S
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 30380 2017-12-17 20:47 CryptoAPI\CryptoAPI.cpp
文件 3437 2017-12-04 08:17 CryptoAPI\CryptoAPI.dsp
文件 526 2017-12-04 09:11 CryptoAPI\CryptoAPI.dsw
文件 41984 2017-12-04 09:11 CryptoAPI\CryptoAPI.ncb
文件 48640 2017-12-04 09:11 CryptoAPI\CryptoAPI.opt
文件 1345 2017-12-04 09:08 CryptoAPI\CryptoAPI.plg
文件 24072192 2017-12-18 10:00 CryptoAPI\CryptoAPI.sdf
文件 3584 2017-12-18 10:00 CryptoAPI\CryptoAPI.suo
文件 6138 2017-12-18 08:03 CryptoAPI\CryptoAPI.vcxproj
文件 143 2017-12-04 09:16 CryptoAPI\CryptoAPI.vcxproj.user
文件 1226 2017-12-17 19:06 CryptoAPI\De.txt
文件 788 2017-12-17 20:50 CryptoAPI\Debug\cl.command.1.tlog
文件 13524 2017-12-17 20:50 CryptoAPI\Debug\CL.read.1.tlog
文件 476 2017-12-17 20:50 CryptoAPI\Debug\CL.write.1.tlog
文件 474624 2017-12-18 08:17 CryptoAPI\Debug\CryptoAPI.exe
文件 406 2017-12-11 07:59 CryptoAPI\Debug\CryptoAPI.exe.em
文件 472 2017-12-11 07:59 CryptoAPI\Debug\CryptoAPI.exe.em
文件 381 2017-12-18 08:17 CryptoAPI\Debug\CryptoAPI.exe.intermediate.manifest
文件 1056180 2017-12-18 08:17 CryptoAPI\Debug\CryptoAPI.ilk
文件 100 2017-12-18 08:17 CryptoAPI\Debug\CryptoAPI.lastbuildstate
文件 2107 2017-12-18 08:17 CryptoAPI\Debug\CryptoAPI.log
文件 60891 2017-12-17 20:50 CryptoAPI\Debug\CryptoAPI.obj
文件 1895424 2017-12-18 08:17 CryptoAPI\Debug\CryptoAPI.pdb
文件 713 2017-12-11 07:59 CryptoAPI\Debug\CryptoAPI.vcxprojResolveAssemblyReference.cache
文件 0 2017-12-11 07:59 CryptoAPI\Debug\CryptoAPI.write.1.tlog
文件 214 2017-12-11 07:59 CryptoAPI\Debug\CryptoAPI_manifest.rc
文件 0 2017-12-18 08:51 CryptoAPI\Debug\En.txt
文件 2 2017-12-18 08:17 CryptoAPI\Debug\li
文件 2 2017-12-18 08:17 CryptoAPI\Debug\li
文件 2 2017-12-18 08:17 CryptoAPI\Debug\li
............此处省略61个文件信息
评论
共有 条评论