[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-cryptoapi
Subject:    Re: CryptSignMessage
From:       "=?iso-8859-1?Q?Ant=F4nio_C=E9sa_da_Silveira_Jr.?="
Date:       2001-02-16 16:09:16
[Download RAW message or body]


 Don´t receive error, a windoows error occur and the application break!!

Do you have some sample using the cryptSignMessage in delphi ?

----- Original Message -----
From: Slawomir Marciniak <Slawek@SUNTECH.COM.PL>
To: <CryptoAPI@DISCUSS.MICROSOFT.COM>
Sent: Friday, February 16, 2001 11:17 AM
Subject: Re: CryptSignMessage


Hi

What error you receive (GetLastError()).

Slawek

-----Original Message-----
From: Antônio Césa da Silveira Jr. [mailto:silveira@DATALAN.COM.BR]
Sent: Friday, February 16, 2001 3:52 PM
To: CryptoAPI@DISCUSS.MICROSOFT.COM
Subject: CryptSignMessage


( repeat ...)
Hello people, I am a Delphi programer (no master) and I´m building a
simple
application that sign and verify signatures. I already build this
application in C ( C++ Builder ) and now I´am porting to Delphi. I am
using
the Crypto API of Jedi project. I am have problems with the
cryptSignMessage, that generate a Windows error in Crypt32.dll . My code
is
below.

The problem ( I believe ) is in the two array parameters, a array of
PByte
 pointers to buffers that will be signed ) and array of Word ( size of
buffers ). I am declaring  they as in the prototype of wcrypt2.pas.   If
you
have a smaple code that sign and verify messages in Delphi using the
cryptSignMessage, please send me.

Thanks in advance.


See my code: ( Obs. The certificate store, HProvider handle are working
corretly, they don´t are show in the code.. )

{ ************************************* }
  pCertContext: PCCERT_CONTEXT ;
  pCertInfo: TCertInfo;
  pszBuffer: PChar;
  pbBuffer:PByte;
  cbBuffer:DWord;
  arqEntra,ArqSai:file;
  lidos:integer;
  SigParams:CRYPT_SIGN_MESSAGE_PARA;
  tamAssinado:DWORD;
  pbAssinado:PBYTE;


 ptamanho:DWORD;

  teste:array[1..2] of PByte;
  tteste:array[1..2] of DWORD;



begin

  pCertInfo:=ListaCertificados.Items[CertificadoAtual];

  pCertContext := CertFindCertificateInStore(hCertStore,
                            X509_ASN_ENCODING or PKCS_7_ASN_ENCODING,
                            0,
                            CERT_FIND_PUBLIC_KEY,
                            @pCertInfo.publicKeyInfo,
                            nil);

  if (pCertContext=nil) then
   begin
    result:=-1; // não encontrou o certificado correspondente
    exit;
   end;

  if(not FileExists(narqEntra)) then
    begin
      result:=-2; // arquivo a ser assinado não existe
      exit;
    end;

  AssignFile(arqEntra,nArqEntra);
  reset(arqEntra,1);
  cbBuffer:=FileSize(arqEntra);
  GetMem(pbBuffer,cbBuffer);
  BlockRead(arqEntra,pbBuffer,cbBuffer,lidos);
  CloseFile(arqEntra);

  teste[1]:=pbBuffer;
  tteste[1]:=cbBuffer;


  if(cbBuffer<>lidos) then
    begin
       result:=-3; // erro na leitura do arquivo;
       exit;
    end;


  MessageArray:=  @pbBuffer ;
 // := cbBuffer;
  pTamanho:=cbBuffer;
  MessageSizeArray:=@pTamanho;
//  pMessageArray:=MessageArray;
//  pMessageSizeArray:=MessageSizeArray;


  SigParams.cbSize := sizeof(CRYPT_SIGN_MESSAGE_PARA);
  SigParams.dwMsgEncodingType := X509_ASN_ENCODING or
PKCS_7_ASN_ENCODING;
  SigParams.pSigningCert := pCertContext;
  SigParams.HashAlgorithm.pszObjId := szOID_RSA_MD5;
  SigParams.HashAlgorithm.Parameters.cbData := 0;
  SigParams.HashAlgorithm.Parameters.pbData := nil;
  SigParams.cMsgCert := 1;
  SigParams.rgpMsgCert := @pCertContext;
  SigParams.cAuthAttr := 0;
  SigParams.dwInnerContentType := 0;
  SigParams.cMsgCrl := 0;
  SigParams.cUnauthAttr := 0;
  SigParams.dwFlags := 0;
  SigParams.pvHashAuxInfo := nil;
  SigParams.rgAuthAttr := nil;

  if (not CryptSignMessage(
                            @sigParams,            // Signature
parameters
                            FALSE,                 // Not detached
                            1,                     // Number of messages
                            teste,          // Messages to be signed
                            tteste,      // Size of messages
                            nil,                  // Buffer for signed
message
                            @tamAssinado)) then // Size of buffer
  begin
      result:=-4;
      exit;
  end;

  GetMem(pbAssinado,tamAssinado);

  if (pbAssinado=nil) then
    begin
       result:=-5;  // : falta de memória para armazenar assinatura
       exit;
    end;


{ ************************************* }

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:CryptoAPI-signoff-request@DISCUSS.MICROSOFT.COM

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:CryptoAPI-signoff-request@DISCUSS.MICROSOFT.COM

----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:CryptoAPI-signoff-request@DISCUSS.MICROSOFT.COM

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic