Compare commits

...

2 Commits

Author SHA1 Message Date
dc3ecb1fc0 BigInteger as string realization 2017-04-20 18:13:10 +03:00
266cef8c49 tests windows 2017-04-20 14:10:38 +03:00
7 changed files with 691 additions and 7 deletions

View File

@ -0,0 +1,435 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef _BUILD_BIGINTEGER_CROSSPLATFORM_H_
#define _BUILD_BIGINTEGER_CROSSPLATFORM_H_
#include <string>
class CBigInteger
{
protected:
std::string m_value;
bool m_isNegative;
public:
CBigInteger()
{
m_value = "0";
m_isNegative = false;
}
CBigInteger(unsigned char* data, int size)
{
m_isNegative = false;
m_value = "0";
for (int i = 0; i < size; i++)
{
int val = 0;
char _c = data[i];
if (_c >= '0' && _c <= '9')
val = _c - '0';
else if (_c >= 'A' && _c <= 'F')
val = 10 + _c - 'A';
else if (_c >= 'a' && _c <= 'f')
val = 10 + _c - 'a';
CBigInteger tmp(val);
for (int j = size - 1 - i; j > 0; --j)
tmp *= 10;
*this += tmp;
}
}
CBigInteger(std::string data, int nBase = 10)
{
m_isNegative = false;
if (10 == nBase)
{
m_value = data;
}
else
{
m_value = "0";
int len = (int)data.length();
for (int i = 0; i < len; i++)
{
int val = 0;
char _c = data[i];
if (_c >= '0' && _c <= '9')
val = _c - '0';
else if (_c >= 'A' && _c <= 'F')
val = 10 + _c - 'A';
else if (_c >= 'a' && _c <= 'f')
val = 10 + _c - 'a';
CBigInteger tmp(val);
for (int j = len - 1 - i; j > 0; --j)
tmp *= nBase;
*this += tmp;
}
}
}
CBigInteger(int value)
{
if (value < 0)
{
m_isNegative = true;
m_value = std::to_string(-value);
}
else
{
m_isNegative = false;
m_value = std::to_string(value);
}
}
std::string GetValue()
{
return m_value;
}
bool IsNegative()
{
return m_isNegative;
}
void operator = (CBigInteger b)
{
m_value = b.m_value;
m_isNegative = b.m_isNegative;
}
bool operator == (CBigInteger b)
{
return equals((*this) , b);
}
bool operator != (CBigInteger b)
{
return !equals((*this) , b);
}
bool operator > (CBigInteger b)
{
return greater((*this) , b);
}
bool operator < (CBigInteger b)
{
return less((*this) , b);
}
bool operator >= (CBigInteger b)
{
return equals((*this) , b) || greater((*this), b);
}
bool operator <= (CBigInteger b)
{
return equals((*this) , b) || less((*this) , b);
}
CBigInteger absolute()
{
return CBigInteger(m_value); // +ve by default
}
CBigInteger& operator ++()
{
// prefix
(*this) = (*this) + 1;
return (*this);
}
CBigInteger operator ++(int)
{
// postfix
CBigInteger before = (*this);
(*this) = (*this) + 1;
return before;
}
CBigInteger& operator --()
{
// prefix
(*this) = (*this) - 1;
return (*this);
}
CBigInteger operator --(int)
{
// postfix
CBigInteger before = (*this);
(*this) = (*this) - 1;
return before;
}
CBigInteger operator + (CBigInteger b)
{
CBigInteger addition;
if (m_isNegative == b.m_isNegative)
{
// both +ve or -ve
addition.m_value = (add(m_value, b.m_value));
addition.m_isNegative = m_isNegative;
}
else
{
// sign different
if (absolute() > b.absolute())
{
addition.m_value = subtract(m_value, b.m_value);
addition.m_isNegative = m_isNegative;
}
else
{
addition.m_value = subtract(b.m_value, m_value);
addition.m_isNegative = b.m_isNegative;
}
}
if (addition.m_value == "0") // avoid (-0) problem
addition.m_isNegative = false;
return addition;
}
CBigInteger operator - (CBigInteger b)
{
b.m_isNegative = !b.m_isNegative; // x - y = x + (-y)
return (*this) + b;
}
CBigInteger operator * (CBigInteger b)
{
CBigInteger mul;
mul.m_value = multiply(m_value, b.m_value);
mul.m_isNegative = (m_isNegative != b.m_isNegative);
if (mul.m_value == "0") // avoid (-0) problem
mul.m_isNegative = false;
return mul;
}
CBigInteger& operator += (CBigInteger b)
{
(*this) = (*this) + b;
return (*this);
}
CBigInteger& operator -= (CBigInteger b)
{
(*this) = (*this) - b;
return (*this);
}
CBigInteger& operator *= (CBigInteger b)
{
(*this) = (*this) * b;
return (*this);
}
CBigInteger operator -() { // unary minus sign
return (*this) * -1;
}
std::string ToString()
{
// for conversion from BigInteger to string
std::string signedString = ( m_isNegative ) ? "-" : ""; // if +ve, don't print + sign
signedString += m_value;
return signedString;
}
private:
bool equals(CBigInteger n1, CBigInteger n2)
{
return ((n1.m_value == n2.m_value) && (n1.m_isNegative == n2.m_isNegative));
}
bool less(CBigInteger n1, CBigInteger n2)
{
bool sign1 = n1.m_isNegative;
bool sign2 = n2.m_isNegative;
if (sign1 && !sign2)
return true;
else if (!sign1 && sign2)
return false;
else if (!sign1)
{
std::string::size_type _size1 = n1.m_value.length();
std::string::size_type _size2 = n2.m_value.length();
if (_size1 < _size2)
return true;
if (_size1 > _size2)
return false;
return n1.m_value < n2.m_value;
}
else
{
std::string::size_type _size1 = n1.m_value.length();
std::string::size_type _size2 = n2.m_value.length();
if (_size1 > _size2)
return true;
if (_size1 < _size2)
return false;
return n1.m_value.compare(n2.m_value) > 0;
}
}
bool greater(CBigInteger n1, CBigInteger n2)
{
return !equals(n1, n2) && !less(n1, n2);
}
std::string add(std::string number1, std::string number2)
{
std::string add = (number1.length() > number2.length()) ? number1 : number2;
char carry = '0';
int differenceInLength = (int)(number1.size() - number2.size());
if (differenceInLength > 0)
number2.insert(0, differenceInLength, '0');
else
number1.insert(0, -differenceInLength, '0');
if (differenceInLength < 0)
differenceInLength = -differenceInLength;
for (int i = number1.size() - 1; i >= 0; --i)
{
add[i] = ((carry-'0')+(number1[i]-'0')+(number2[i]-'0')) + '0';
if(i != 0)
{
if(add[i] > '9')
{
add[i] -= 10;
carry = '1';
}
else
{
carry = '0';
}
}
}
if (add[0] > '9')
{
add[0] -= 10;
add.insert(0, 1, '1');
}
return add;
}
std::string subtract(std::string number1, std::string number2)
{
std::string sub = (number1.length() > number2.length()) ? number1 : number2;
int differenceInLength = (int)(number1.size() - number2.size());
if (differenceInLength > 0)
number2.insert(0, differenceInLength, '0');
else
number1.insert(0, -differenceInLength, '0');
if (differenceInLength < 0)
differenceInLength = -differenceInLength;
for (int i = number1.length() - 1; i >= 0; --i)
{
if (number1[i] < number2[i])
{
number1[i] += 10;
number1[i-1]--;
}
sub[i] = ((number1[i]-'0')-(number2[i]-'0')) + '0';
}
while (sub[0]=='0' && sub.length() != 1) // erase leading zeros
sub.erase(0, 1);
return sub;
}
std::string multiply(std::string n1, std::string n2)
{
if (n1.length() > n2.length())
n1.swap(n2);
std::string res = "0";
for (int i = n1.length() - 1; i >= 0; --i)
{
std::string temp = n2;
int currentDigit = n1[i] - '0';
int carry = 0;
for (int j = temp.length() - 1; j >= 0; --j)
{
temp[j] = ((temp[j]-'0') * currentDigit) + carry;
if (temp[j] > 9)
{
carry = (temp[j] / 10);
temp[j] -= (carry * 10);
}
else
{
carry = 0;
}
temp[j] += '0'; // back to string mood
}
if (carry > 0)
temp.insert(0, 1, (carry+'0'));
temp.append((n1.length() - i - 1), '0'); // as like mult by 10, 100, 1000, 10000 and so on
res = add(res, temp); // O(n)
}
while (res[0] == '0' && res.length() != 1) // erase leading zeros
res.erase(0,1);
return res;
}
};
#endif //_BUILD_BIGINTEGER_CROSSPLATFORM_H_

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sha1_C14N", "ConsoleApplication1\Sha1_C14N.csproj", "{A945E071-111A-41E0-8BB0-4F7755EBB77B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A945E071-111A-41E0-8BB0-4F7755EBB77B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Security.Cryptography.X509Certificates;
using System.IO;
namespace Sha1_C14N
{
class Program
{
static void Main(string[] args)
{
XmlDocument docStripped = new XmlDocument();
//docStripped.Load(@"D:\GIT\core\DesktopEditor\xmlsec\test\windows_list_serts\Debug\debug\document.xml");
docStripped.Load("D:\\444.txt");
XmlDsigC14NTransform t = new XmlDsigC14NTransform();
t.LoadInput(docStripped);
Stream s = (Stream)t.GetOutput(typeof(Stream));
BinaryReader br = new BinaryReader(s);
byte[] b = br.ReadBytes((int)s.Length);
File.Delete("D:\\1.txt");
var fileStream = File.Create("D:\\1.txt");
s.Seek(0, SeekOrigin.Begin);
s.CopyTo(fileStream);
fileStream.Close();
s.Seek(0, SeekOrigin.Begin);
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(s);
string base64String = Convert.ToBase64String(hash);
FileStream fRes = File.Create("D:\\res.bin");
fRes.Write(hash, 0, hash.Length);
fRes.Close();
SHA1 sha33 = SHA1.Create();
byte[] hash33 = sha33.ComputeHash(b);
string base64String2 = Convert.ToBase64String(hash33);
FileStream s1 = File.OpenRead(@"D:\GIT\core\DesktopEditor\xmlsec\test\windows_list_serts\Debug\debug\document2.xml");
SHA1 sha11 = SHA1.Create();
byte[] hash11 = sha11.ComputeHash(s1);
string base64_11 = Convert.ToBase64String(hash11);
X509Store my = new X509Store(StoreName.My, StoreLocation.CurrentUser);
my.Open(OpenFlags.ReadOnly);
// Find the certificate well use to sign
RSACryptoServiceProvider csp = null;
foreach (X509Certificate2 cert in my.Certificates)
{
string sName = cert.Subject;
if (cert.Subject.Contains("Oleg.Korshul"))
{
csp = (RSACryptoServiceProvider)cert.PrivateKey;
break;
}
}
byte[] signedData = csp.SignHash(hash11, CryptoConfig.MapNameToOID("SHA1"));
string signedDataBase64 = Convert.ToBase64String(signedData);
Console.WriteLine(base64_11);
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Управление общими сведениями о сборке осуществляется с помощью
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
// связанные со сборкой.
[assembly: AssemblyTitle("Sha1_C14N")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sha1_C14N")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Параметр ComVisible со значением FALSE делает типы в сборке невидимыми
// для COM-компонентов. Если требуется обратиться к типу в этой сборке через
// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
[assembly: ComVisible(false)]
// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
[assembly: Guid("a945e071-111a-41e0-8bb0-4f7755ebb77b")]
// Сведения о версии сборки состоят из следующих четырех значений:
//
// Основной номер версии
// Дополнительный номер версии
// Номер сборки
// Редакция
//
// Можно задать все значения или принять номера сборки и редакции по умолчанию
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A945E071-111A-41E0-8BB0-4F7755EBB77B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConsoleApplication1</RootNamespace>
<AssemblyName>ConsoleApplication1</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Security" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -7,6 +7,7 @@
#include <string>
#include "../../../common/File.h"
#include "../../../common/BigInteger.h"
#pragma comment (lib, "crypt32.lib")
#pragma comment (lib, "cryptui.lib")
@ -20,8 +21,26 @@ void MyHandleError(char *s);
bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile);
bool Verify(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFileXml, std::wstring sSignatureFile);
void ConvertEndian(const BYTE* src, BYTE* dst, DWORD size)
{
for(BYTE* p = dst + size - 1; p >= dst; ++src, --p)
(*p) = (*src);
}
void main(void)
{
if (false)
{
CBigInteger int1("345097");
CBigInteger int2("87960324");
CBigInteger val1 = int1 + int2;
CBigInteger val2 = int1 - int2;
CBigInteger val3 = int1 * int2;
CBigInteger int3("66A1F302407647974D18D489855371B5", 16);
std::string sValue = int3.ToString();
}
//-------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
@ -312,8 +331,8 @@ void main(void)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool bRes = true;
bRes = Sign(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Verify(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Sign(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document2.xml", NSFile::GetProcessDirectory() + L"/result.txt");
bRes = Verify(hCertStore, pCertContext, NSFile::GetProcessDirectory() + L"/document2.xml", NSFile::GetProcessDirectory() + L"/result.txt");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CertFreeCertificateContext(pCertContext);
@ -342,8 +361,6 @@ bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFi
DWORD dwSigLen = 0;
BYTE* pbSignature = NULL;
// Open the certificate store.
bResult = CryptAcquireCertificatePrivateKey(pCertContext, 0, NULL, &hCryptProv, &dwKeySpec, NULL);
bool bIsResult = ((dwKeySpec & AT_SIGNATURE) == AT_SIGNATURE);
@ -357,6 +374,23 @@ bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFi
bResult = CryptHashData(hHash, pDataSrc, dwFileSrcLen, 0);
if (true)
{
DWORD cbHashSize = 0, dwCount = sizeof(DWORD);
BOOL b1 = CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE*)&cbHashSize, &dwCount, 0);
BYTE* pDataHashRaw = new BYTE[dwCount];
BOOL b2 = CryptGetHashParam(hHash, HP_HASHVAL, pDataHashRaw, &cbHashSize, 0);
char* pBase64_hash = NULL;
int nBase64Len_hash = 0;
NSFile::CBase64Converter::Encode(pDataHashRaw, (int)cbHashSize, pBase64_hash, nBase64Len_hash, NSBase64::B64_BASE64_FLAG_NONE);
delete [] pBase64_hash;
}
// Sign the hash object
dwSigLen = 0;
bResult = CryptSignHash(hHash, dwKeySpec, NULL, 0, NULL, &dwSigLen);
@ -364,18 +398,27 @@ bool Sign(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring sFi
pbSignature = new BYTE[dwSigLen];
bResult = CryptSignHash(hHash, dwKeySpec, NULL, 0, pbSignature, &dwSigLen);
NSFile::CFileBinary oFileTmp;
oFileTmp.CreateFileW(NSFile::GetProcessDirectory() + L"/HASH.bin");
oFileTmp.WriteFile(pbSignature, dwSigLen);
oFileTmp.CloseFile();
BYTE* pbSignatureMem = new BYTE[dwSigLen];
ConvertEndian(pbSignature, pbSignatureMem, dwSigLen);
NSFile::CFileBinary oFile;
oFile.CreateFileW(sSignatureFile);
//oFile.WriteFile(pbSignature, dwSigLen);
char* pBase64 = NULL;
int nBase64Len = 0;
NSFile::CBase64Converter::Encode(pbSignature, (int)dwSigLen, pBase64, nBase64Len, NSBase64::B64_BASE64_FLAG_NONE);
NSFile::CBase64Converter::Encode(pbSignatureMem, (int)dwSigLen, pBase64, nBase64Len, NSBase64::B64_BASE64_FLAG_NONE);
oFile.WriteFile((BYTE*)pBase64, (DWORD)nBase64Len);
oFile.CloseFile();
delete[] pbSignature;
delete[] pbSignatureMem;
delete[] pDataSrc;
bResult = CryptDestroyHash(hHash);
@ -409,18 +452,22 @@ bool Verify(HCERTSTORE hStoreHandle, PCCERT_CONTEXT pCertContext, std::wstring s
NSFile::CBase64Converter::Decode((char*)pDataHashBase64, (int)dwFileHashSrcLenBase64, pDataHash, nTmp);
dwHashLen = (DWORD)nTmp;
BYTE* pDataHashMem = new BYTE[dwHashLen];
ConvertEndian(pDataHash, pDataHashMem, dwHashLen);
bResult = CryptHashData(hHash, pDataSrc, dwFileSrcLen, 0);
// Get the public key from the certificate
CryptImportPublicKeyInfo(hCryptProv, PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, &pCertContext->pCertInfo->SubjectPublicKeyInfo, &hPubKey);
bResult = CryptVerifySignature(hHash, pDataHash, dwHashLen, hPubKey, NULL, 0);
BOOL bResultRet = CryptVerifySignature(hHash, pDataHashMem, dwHashLen, hPubKey, NULL, 0);
delete[] pDataSrc;
delete[] pDataHash;
delete[] pDataHashMem;
delete[] pDataHashBase64;
bResult = CryptDestroyHash(hHash);
return bResult;
return bResultRet && bResult;
}