使用Microsoft CryptoAPI进行加密、解密、签名及验证(代码)
来源:互联网 发布:萨克雷日本联赛数据 编辑:程序博客网 时间:2024/06/05 21:00
#include <stdio.h>
#include <windows.h>
#include <wincrypt.h>
#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.
void main(void)
{
CHAR szSource[100];
CHAR szDestination[100];
CHAR szPassword[100];
//--------------------------------------------------------------------
// 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!");
}
//--------------------------------------------------------------------
// 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!");
}
//--------------------------------------------------------------------
// Call SignFile to do the actual signature 签名文件
printf("/n------------------------------------------------------------/n");
printf("/n/n3.Sign a file. /n/n");
printf("/nEnter the name of the file to be signed: ");
scanf("%s",szSource);
printf("/nEnter the name of the signature file: ");
scanf("%s",szDestination);
if(SignFile(szSource, szDestination))
{
printf("/nSignature of the file %s was a success. /n", szSource);
printf("/nThe signature data is in file %s./n",szDestination);
}
else
{
HandleError("/nError while signing the file!");
}
//---------------------------------------------------------------------
// Call VerifyFile to do the actual verification 验证签名
printf("/n------------------------------------------------------------/n");
printf("/n/n4.Verify a file and its signature. /n/n");
printf("/nEnter the name of the file to be verified: ");
scanf("%s",szSource);
printf("/nEnter the name of the signature file: ");
scanf("%s",szDestination);
//printf("/nEnter the name of the public key file: ");
//scanf("%s",szDestination);
if(VerifyFile(szSource, szDestination))
{
printf("/nVerification of the file %s was a success. /n", szSource);
}
else
{
HandleError("/nVerification failed. Error file!");
}
} // End of main
- 使用Microsoft CryptoAPI进行加密、解密、签名及验证(代码)
- 使用Microsoft CryptoAPI进行加密、解密、签名及验证
- 使用Microsoft CryptoAPI进行加密、解密、签名及验证
- 使用Microsoft CryptoAPI进行加密、解密、签名及验证 (转发)
- 使用CryptoAPI对文件进行加密解密
- .NET Core 使用RSA算法 加密/解密/签名/验证签名
- php接口数据加密、解密、验证签名代码实例
- Microsoft CryptoAPI加密技术
- Microsoft CryptoAPI加密技术
- Microsoft CryptoAPI加密技术
- Microsoft CryptoAPI加密技术
- Microsoft CryptoAPI加密技术
- Microsoft CryptoAPI加密技术
- Microsoft CryptoAPI 加密
- Microsoft CryptoAPI加密技术
- RSA加密解密及RSA签名和验证
- RSA加密解密及RSA签名和验证
- RSA加密解密及RSA签名和验证(转)
- PHP初学者常见问题及解决办法
- 通信界行业排名?
- 留住非法网络入侵者的作案痕迹
- 搞笑求婚方式 ^_^
- 如何在你的Linux机器上安装运行Oracle
- 使用Microsoft CryptoAPI进行加密、解密、签名及验证(代码)
- Linux常用命令
- C#3.0 中使用扩展方法来扩展接口
- 腾讯最新概念设计
- java action 中 跳出js提示框
- The SWT FAQ 中文(7)
- SQL Server数据类型介绍
- 利用apache建立虚拟主机(基于端口)
- 什么DAO设计模式