天天看點

軟體數字簽名 c語言,數字簽名,該怎麼解決

目前位置:我的異常網» C語言 » 數字簽名,該怎麼解決

數字簽名,該怎麼解決

www.myexceptions.net  網友分享于:2013-05-23  浏覽:74次

數字簽名

請問大神們,關于數字簽名有沒有什麼比較新穎的算法,謝謝!

------解決方案--------------------

#include

#include

#include

#include

#include

#pragma comment(lib, "crypt32.lib")

#define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING)

typedef struct {

LPWSTR lpszProgramName;

LPWSTR lpszPublisherLink;

LPWSTR lpszMoreInfoLink;

} SPROG_PUBLISHERINFO, *PSPROG_PUBLISHERINFO;

BOOL GetProgAndPublisherInfo(PCMSG_SIGNER_INFO pSignerInfo,

PSPROG_PUBLISHERINFO Info);

BOOL GetDateOfTimeStamp(PCMSG_SIGNER_INFO pSignerInfo, SYSTEMTIME *st);

BOOL PrintCertificateInfo(PCCERT_CONTEXT pCertContext);

BOOL GetTimeStampSignerInfo(PCMSG_SIGNER_INFO pSignerInfo,

PCMSG_SIGNER_INFO *pCounterSignerInfo);

int _tmain(int argc, TCHAR *argv[])

{

WCHAR szFileName[MAX_PATH];

HCERTSTORE hStore = NULL;

HCRYPTMSG hMsg = NULL;

PCCERT_CONTEXT pCertContext = NULL;

BOOL fResult;

DWORD dwEncoding, dwContentType, dwFormatType;

PCMSG_SIGNER_INFO pSignerInfo = NULL;

PCMSG_SIGNER_INFO pCounterSignerInfo = NULL;

DWORD dwSignerInfo;

CERT_INFO CertInfo;

SPROG_PUBLISHERINFO ProgPubInfo;

SYSTEMTIME st;

ZeroMemory(&ProgPubInfo, sizeof(ProgPubInfo));

__try

{

if (argc != 2)

{

_tprintf(_T("Usage: SignedFileInfo \n"));

return 0;

}

#ifdef UNICODE

lstrcpynW(szFileName, argv[1], MAX_PATH);

#else

if (mbstowcs(szFileName, argv[1], MAX_PATH) == -1)

{

printf("Unable to convert to unicode.\n");

__leave;

}

#endif

// Get message handle and store handle from the signed file.

fResult = CryptQueryObject(CERT_QUERY_OBJECT_FILE,

szFileName,

CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED,

CERT_QUERY_FORMAT_FLAG_BINARY,

0,

&dwEncoding,

&dwContentType,

&dwFormatType,

&hStore,

&hMsg,

NULL);

if (!fResult)

{

_tprintf(_T("CryptQueryObject failed with %x\n"), GetLastError());

__leave;

}

// Get signer information size.

fResult = CryptMsgGetParam(hMsg,

CMSG_SIGNER_INFO_PARAM,

0,

NULL,

&dwSignerInfo);

if (!fResult)

{

_tprintf(_T("CryptMsgGetParam failed with %x\n"), GetLastError());

__leave;

}

// Allocate memory for signer information.

pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfo);

if (!pSignerInfo)

{

_tprintf(_T("Unable to allocate memory for Signer Info.\n"));

__leave;

}

// Get Signer Information.

fResult = CryptMsgGetParam(hMsg,

CMSG_SIGNER_INFO_PARAM,

0,

(PVOID)pSignerInfo,

&dwSignerInfo);

文章評論