AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

Ein Thema von Back2Code · begonnen am 7. Sep 2015 · letzter Beitrag vom 7. Sep 2015
Antwort Antwort
Benutzerbild von Back2Code
Back2Code

Registriert seit: 6. Feb 2012
Ort: Deutschland
272 Beiträge
 
Delphi XE7 Professional
 
#1

Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 10:28
Guten Morgen DP'ler,

ich arbeite derzeit mit dem Interface von dem CryptoSys PKI (http://www.cryptosys.net/delphi.html)

Hier mal ein Auszug aus dem Interface

Delphi-Quellcode:
.
.
function CMS_ReadSigDataToString(szDataOut : PAnsiChar; nDataOutLen : Integer; szFileIn : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
.
.
szDataOut ist der Parameter den ich als Rückgabewert erwarte / mit dem ich arbeiten muss da dieser den entschlüsselten String enthält.

Die Deklaration als normaler String fiel schonmal weg, dann hab ich es als strData: Array [0..40] of Ansichar; deklariert und bekomme auch die richtigen Rückgabewerte das Problem hierbei ist allerdings, dass damit die Länge des Rückgabewertes bereits vordefiniert ist und ich logischerweise ne dicke Exception bekomme, sobald der Output größer als 40 Chars ist.

Was kann ich machen um die Länge des Arrays passend zu dem Output zu definieren, dass nichts fehlt/abgeschnitten ist? Beim Versuch ein dynamisches Array zu nutzen bekam ich:

Code:
[dcc32 Fehler] uMain.pas(435): E2010 Inkompatible Typen: 'PAnsiChar' und 'Dynamic array'
Aufruf:
nRet := CMS_ReadSigDataToString(strData, nDataLen, strSigFile, 0); Codeauszug:

Delphi-Quellcode:
var
  strData: Array [0..40] of Ansichar;
  nDataLen: Integer;
begin
    // Read in the recipient's private key
    strPrivateKey := rsaReadPrivateKey(strPriKeyFile, strPassword);
    if Length(strPrivateKey) = 0
      then begin
        WriteDebugMessage('Schlüssel konnte nicht eingelesen werden.');
      end
      else begin
        WriteDebugMessage('Schlüssel erfolgreich gelesen' + #13#10 + 'Schlüssellänge in Bits: ' + IntToStr(RSA_KeyBits(strPrivateKey)));
      end;

    // Intermediate file we will create
    strSigFile := strInputFile + '.i2.tmp';

    // Read the encrypted data from the enveloped-data file
    nRet := CMS_ReadEnvData(strSigFile, strInputFile, '', strPrivateKey, 0); //
    WriteDebugMessage('CMS_ReadEnvData returns ' + IntToStr(nRet) + ' (expected 0)');
    if nRet <> 0
      then begin
        WriteDebugMessage('**ERROR** while reading the encrypted data from the enveloped-data file');
      end
      else
      begin
        WriteDebugMessage('Extracted signed-data file ' + strSigFile);
      end;

    //How long is the content to be read?
    nDataLen := CMS_ReadSigDataToString('', 0, strSigFile, 0);
    if nDataLen <= 0
    then begin
      WriteDebugMessage('Cannot read signed-data file');
    end
   else
   begin
     nRet := CMS_ReadSigDataToString(strData, nDataLen, strSigFile, 0);
      WriteDebugMessage('CMS_ReadSigDataToString returns ' + IntToStr(nRet));
      WriteDebugMessage('Data is [' + strData + ']');
      Result := strData;
   end;
00111100001100110010000001000100011001010110110001 1100000110100001101001
  Mit Zitat antworten Zitat
nahpets
(Gast)

n/a Beiträge
 
#2

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 11:01
geht das denn nicht mitvar strData : PAnsiChar;
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 11:19
geht das denn nicht mitvar strData : PAnsiChar;
Bloss nicht ...

Sobald man die benötigte Länge kennt, bereitet man den Bereich entsprechend vor und übergibt den Pointer auf den Bereich. In diesen Bereich wird dann hinein geschrieben.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
HolgerX

Registriert seit: 10. Apr 2006
Ort: Leverkusen
961 Beiträge
 
Delphi 6 Professional
 
#4

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 11:32
Frage vorweg:
Hast Du Dir die Beschreibung der API mal angeschaut?

http://www.cryptosys.net/pki/manpki/...aToString.html

Zitat:
Remarks
This function extracts the signed data from the signed-data CMS object without making any attempt to verify it. Call the function with an empty or NULL szOutput string or zero nOutChars parameter to find out the required length of the output string.

Aus dem Bauch heraus:

Code:
function ReadSigData(AFileName : AnsiString):AnsiString;
var
  tmpBuffer : PChar;
  tmpBuferSize : integer;
  tmpRead : integer;
  tmpResult : integer;
begin
  // Benötigten Buffer ermitteln
  tmpBuferSize := CMS_ReadSigDataToString(nil, 0,AFileName,0);
  if tmpBuferSize > 0 then begin
    // Buffer anlegen
    tmpBuffer := AllocMem(tmpBuferSize+1);
    try
      // Sicherheitshalber löschen
      FillChar(tmpBuffer,tmpBuferSize+1,0);
      // Funktionsaufruf
      tmpRead := CMS_ReadSigDataToString(tmpBuffer, tmpBuferSize,AFileName,0);
      // Wenn (wirklich) Daten vorhanden
      if (tmpRead > 0) then begin
        // .. zurückgeben.
        result := tmpBuffer;
      end;
    finally
      // Buffer wiedere freigeben
      FreeMem(tmpBuffer);
    end;
  end;
end;
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#5

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 12:23
Oder kurz und DRY
Delphi-Quellcode:
unit Unit1;

interface

uses
  SysUtils;

type
  CryptoSysException = class( Exception );

function ReadSigData( AFileName: AnsiString ): AnsiString;

implementation

{$DEFINE MAYBE_BETTER}
function CMS_ReadSigDataToString(
  szDataOut : PAnsiChar;
  nDataOutLen: Integer;
  szFileIn : {$IFDEF MAYBE_BETTER}PAnsiChar{$ELSE}AnsiString{$ENDIF};
  nOptions : Integer ): Integer; stdcall; external 'diCrPKI.dll';

function ReadSigData( AFileName: AnsiString ): AnsiString;
var
  szDataOut : PAnsiChar;
  nDataOutLen: Integer;
  szFileIn : {$IFDEF MAYBE_BETTER}PAnsiChar{$ELSE}AnsiString{$ENDIF};
  nOptions : Integer;
begin
  szDataOut := nil;
  nDataOutLen := 0;
  szFileIn := {$IFDEF MAYBE_BETTER}PAnsiChar( AFileName ){$ELSE}AFileName{$ENDIF};
  nOptions := 0;

  while True do
    begin
      nDataOutLen := CMS_ReadSigDataToString(
        szDataOut,
        nDataOutLen,
        szFileIn,
        nOptions );
      if nDataOutLen <= 0
      then
        raise CryptoSysException.Create( 'API call failed' ); // o.ä.

      SetLength( Result, nDataOutLen );
      if szDataOut <> nil
      then
        Break;
      szDataOut := PAnsiChar( Result );
    end;
end;

end.
Das mit dem AnsiString Parameter wundert mich doch schon sehr ... sicher, dass das kein PAnsiChar ist?
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Benutzerbild von Back2Code
Back2Code

Registriert seit: 6. Feb 2012
Ort: Deutschland
272 Beiträge
 
Delphi XE7 Professional
 
#6

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 14:22
Das mit dem AnsiString Parameter wundert mich doch schon sehr ... sicher, dass das kein PAnsiChar ist?
So stehts zumindest in der Unit deklariert hab da ja nichts dran geändert die wurde so ausgeliefert.

Hat jetzt mit

Delphi-Quellcode:
      GetMem(strData, nDataLen + 1);
      FreeMem(strData, nDataLen + 1);
geklappt
00111100001100110010000001000100011001010110110001 1100000110100001101001
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#7

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 14:38
Ich hab dann auch nochmal geschaut und was sehen wir?
Delphi-Quellcode:
function CMS_ReadSigDataToString(
  szDataOut:Pchar;
  nDataOutLen:longint;
  szFileIn:Pchar;
  nOptions:longint):longint;cdecl;
  external External_library name 'CMS_ReadSigDataToString';
Also doch ein Pointer. Dass es mit AnsiString funktioniert ist eher Zufall.

Ach ja, das mit dem PChar haben die auch nicht verstanden.
Zitat:
Strings and byte arrays that receive output need to be pre-dimensioned to the correct length before calling a DLL function. Then pass a Pointer as the parameter.
Delphi-Quellcode:
buf : AnsiString;
//...
buf := AnsiString(StringOfChar(#0,nchars));
ret := FOO_StringFunction(Pointer(buf), nchars, ...);
arrbytes : Array of Byte;
//...
SetLength(arrbytes, nbytes);
ret := FOO_ByteFunction(Pointer(arrbytes), nbytes, ...);
These output parameters are expected as PChar PAnsiChar and PByte respectively. [PChar also seemed to work OK for us in early tests and the compiler didn't complain either].
Und nun reservierst du Speicher um diesen in einen anderen Bereich zu kopieren und dann den reservierten wieder zu verwerfen. Gut, das kann man machen, muss man aber nicht.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo ( 7. Sep 2015 um 14:40 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Back2Code
Back2Code

Registriert seit: 6. Feb 2012
Ort: Deutschland
272 Beiträge
 
Delphi XE7 Professional
 
#8

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 14:54
@Rufo ich nutze das Interface von 2010. das neueste war bei mir nicht kompilierbar

Delphi-Quellcode:
{
  Delphi function declarations for CryptoSys PKI
  $Id: diCrPKI.pas $
  Copyright (C) 2010 DI Management Services Pty Limited.
  All rights reserved. <www.di-mgt.com.au> <www.cryptosys.net>
  Provided as is with no warranties. Use at your own risk.
  Last updated:
    $Date: 2010-03-17 07:26 $
    $Revision: 3.4.0 $
}

   // GENERAL FUNCTIONS
   function PKI_Version(reserved1 : PByte; reserved2 : PByte) : Integer; stdcall; external 'diCrPKI.dll';
   function PKI_LicenceType(reserved : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PKI_LastError(szErrMsg : PAnsiChar; nMsgLen : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PKI_ErrorCode : Integer; stdcall; external 'diCrPKI.dll';
   function PKI_ErrorLookup(szErrMsg : PAnsiChar; nMsgLen : Integer; nErrCode : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PKI_CompileTime(szOutput : PAnsiChar; nOutputLen : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PKI_ModuleName(szOutput : PAnsiChar; nOutputLen : Integer; reserved : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PKI_PowerUpTests(nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // RFC3369 CRYPTOGRAPHIC MESSAGE SYNTAX FUNCTIONS
   function CMS_MakeEnvData(szFileOut : AnsiString; szFileIn : AnsiString; szCertList : AnsiString; sSeed : AnsiString; nSeedLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_MakeEnvDataFromString(szFileOut : AnsiString; szDataIn : AnsiString; szCertList : AnsiString; sSeed : AnsiString; nSeedLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_ReadEnvData(szFileOut : AnsiString; szFileIn : AnsiString; szX509File : AnsiString; szRSAPrivateKey : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_ReadEnvDataToString(szDataOut : PAnsiChar; nDataOutLen : Integer; szFileIn : AnsiString; szX509File : AnsiString; szRSAPrivateKey : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_MakeSigData(szFileOut : AnsiString; szFileIn : AnsiString; szCertList : AnsiString; szRSAPrivateKey : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_MakeSigDataFromString(szFileOut : AnsiString; szDataIn : AnsiString; szCertList : AnsiString; szRSAPrivateKey : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_MakeSigDataFromSigValue(szFileOut : AnsiString; pSigValue : PByte; nSigLen : Integer; pData : PByte; nDataLen : Integer; szCertList : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_MakeDetachedSig(szFileOut : AnsiString; szHexDigest : AnsiString; szCertList : AnsiString; szRSAPrivateKey : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_ReadSigData(szFileOut : AnsiString; szFileIn : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_ReadSigDataToString(szDataOut : PAnsiChar; nDataOutLen : Integer; szFileIn : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_GetSigDataDigest(szHexDigestOut : PAnsiChar; nDigestLen : Integer; szFileIn : AnsiString; szX509File : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_VerifySigData(szFileIn : AnsiString; szX509File : AnsiString; szHexDigest : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_QuerySigData(szDataOut : PAnsiChar; nDataOutLen : Integer; szFileIn : AnsiString; szQuery : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CMS_QueryEnvData(szDataOut : PAnsiChar; nDataOutLen : Integer; szFileIn : AnsiString; szQuery : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // RSA KEY FUNCTIONS
   function RSA_MakeKeys(szPubKeyFile : AnsiString; szPVKFile : AnsiString; nBits : Integer; nExpFermat : Integer; nTests : Integer; nCount : Integer; szPassword : AnsiString; lpSeed : PByte; nSeedLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_ReadEncPrivateKey(szOutput : PAnsiChar; nOutputLen : Integer; szPVKFile : AnsiString; szPassword : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_ReadPrivateKeyInfo(szOutput : PAnsiChar; nOutputLen : Integer; szKeyFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_GetPrivateKeyFromPFX(szOutputFile : AnsiString; szPFXFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_ReadPublicKey(szOutput : PAnsiChar; nOutputLen : Integer; szKeyFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_GetPublicKeyFromCert(szOutput : PAnsiChar; nOutputLen : Integer; szCertFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_SavePublicKey(szFileOut : AnsiString; szKeyString : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_SavePrivateKeyInfo(szFileOut : AnsiString; szKeyString : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_SaveEncPrivateKey(szFileOut : AnsiString; szKeyString : AnsiString; nCount : Integer; szPassword : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_KeyBits(szKeyString : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_KeyBytes(szKeyString : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_ToXMLString(szOutput : PAnsiChar; nOutputLen : Integer; szKeyString : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_FromXMLString(szOutput : PAnsiChar; nOutputLen : Integer; szXmlString : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_CheckKey(szKeyString : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_KeyHashCode(szKeyString : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_KeyMatch(szPrivateKey : AnsiString; szPublicKey : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   
   // 'RAW' RSA ENCRYPTION/DECRYPTION FUNCTIONS
   function RSA_RawPublic(lpData : PByte; nDataLen : Integer; szPublicKey64 : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_RawPrivate(lpData : PByte; nDataLen : Integer; szPrivateKey64 : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_EncodeMsg(lpOutput : PByte; nOutputLen : Integer; abMessage : PByte; nMsgLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RSA_DecodeMsg(lpOutput : PByte; nOutputLen : Integer; abInput : PByte; nInputLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
    
   //Custom 2015
   function RSA_ReadAnyPrivateKey(szOutput : PAnsiChar; nOutputLen : Integer; szPVKFile : AnsiString; szPassword : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function ASN1_TextDump(strFileOut: AnsiString; strFileOrPEMString: AnsiString; nOptions: Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function ASN1_Type(strOutput: AnsiString; nOutChars: Integer; strFileOrPEMString: AnsiString; nOptions: Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // PKCS12 FILE FUNCTIONS
   function PFX_MakeFile(szFileOut : AnsiString; szCertFile : AnsiString; szKeyFile : AnsiString; szPassword : AnsiString; szFriendlyName : AnsiString; options : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PFX_VerifySig(szFileName : AnsiString; szPassword : AnsiString; options : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // X509 CERTIFICATE FUNCTIONS
   function X509_MakeCert(certfile : AnsiString; issuerCert : AnsiString; subjectPubkeyFile : AnsiString; issuerPvkInfoFile : AnsiString; certnum : Integer; yearsvalid : Integer; distName : AnsiString; extensions : AnsiString; keyUsageFlags : Integer; password : AnsiString; optionFlags : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_MakeCertSelf(certfile : AnsiString; epkfile : AnsiString; certnum : Integer; yearsvalid : Integer; distName : AnsiString; extensions : AnsiString; keyUsageFlags : Integer; password : AnsiString; optionFlags : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertRequest(reqfile : AnsiString; epkfile : AnsiString; distName : AnsiString; reserved : AnsiString; password : AnsiString; optionFlags : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_VerifyCert(szCertToVerify : AnsiString; szIssuerCert : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertThumb(szCertFile : AnsiString; szHash : PAnsiChar; nHashLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertIsValidNow(szCertFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertIssuedOn(szCertFile : AnsiString; szOutput : PAnsiChar; nOutChars : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertExpiresOn(szCertFile : AnsiString; szOutput : PAnsiChar; nOutChars : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertSerialNumber(szCertFile : AnsiString; szOutput : PAnsiChar; nOutChars : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_HashIssuerAndSN(szCertFile : AnsiString; szOutput : PAnsiChar; nOutChars : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertIssuerName(szCertFile : AnsiString; szOutput : PAnsiChar; nOutChars : Integer; szDelim : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_CertSubjectName(szCertFile : AnsiString; szOutput : PAnsiChar; nOutChars : Integer; szDelim : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_GetCertFromP7Chain(szNewCertFile : AnsiString; szP7cFile : AnsiString; nIndex : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_GetCertFromPFX(szNewCertFile : AnsiString; szPfxFile : AnsiString; szReserved : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_KeyUsageFlags(szCertFile : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_QueryCert(szOutput : PAnsiChar; nOutChars : Integer; szCertFile : AnsiString; szQuery : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_ReadStringFromFile(szOutput : PAnsiChar; nOutChars : Integer; szCertFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function X509_SaveFileFromString(szNewCertFile : AnsiString; szCertString : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // TRIPLE DES FUNCTIONS
   function TDEA_HexMode(szOutput : PAnsiChar; szInput : AnsiString; szKey : AnsiString; fEncrypt : Integer; szMode : AnsiString; szIV : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function TDEA_B64Mode(szOutput : PAnsiChar; szInput : AnsiString; szKey : AnsiString; fEncrypt : Integer; szMode : AnsiString; szIV : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function TDEA_BytesMode(lpOutput : PByte; lpInput : PByte; nBytes : Integer; lpKey : PByte; fEncrypt : Integer; szMode : AnsiString; lpIV : PByte) : Integer; stdcall; external 'diCrPKI.dll';
   function TDEA_File(szFileOut : AnsiString; szFileIn : AnsiString; lpKey : PByte; fEncrypt : Integer; szMode : AnsiString; lpIV : PByte) : Integer; stdcall; external 'diCrPKI.dll';
   
   // GENERIC BLOCK CIPHER FUNCTIONS
   function CIPHER_Bytes(fEncrypt : Integer; lpOutput : PByte; lpData : PByte; nDataLen : Integer; lpKey : PByte; lpIV : PByte; szAlgAndMode : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CIPHER_File(fEncrypt : Integer; szFileOut : AnsiString; szFileIn : AnsiString; lpKey : PByte; lpIV : PByte; szAlgAndMode : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CIPHER_Hex(fEncrypt : Integer; szOutput : PAnsiChar; nOutChars : Integer; szData : AnsiString; szKey : AnsiString; szIV : AnsiString; szAlgAndMode : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CIPHER_KeyWrap(lpOutput : PByte; nOutBytes : Integer; lpData : PByte; nDataLen : Integer; lpKEK : PByte; nKekLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CIPHER_KeyUnwrap(lpOutput : PByte; nOutBytes : Integer; lpData : PByte; nDataLen : Integer; lpKEK : PByte; nKekLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // MESSAGE DIGEST HASH FUNCTIONS
   function HASH_Bytes(lpDigest : PByte; nDigLen : Integer; lpMessage : PByte; nMsgLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function HASH_File(lpDigest : PByte; nDigLen : Integer; szFileName : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function HASH_HexFromBytes(szOutput : PAnsiChar; nOutChars : Integer; lpMessage : PByte; nMsgLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function HASH_HexFromFile(szOutput : PAnsiChar; nOutChars : Integer; szFileName : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function HASH_HexFromHex(szOutput : PAnsiChar; nOutChars : Integer; szMsgHex : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // HMAC FUNCTIONS
   function HMAC_Bytes(lpDigest : PByte; nDigLen : Integer; lpMessage : PByte; nMsgLen : Integer; lpKey : PByte; nKeyLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function HMAC_HexFromBytes(szOutput : PAnsiChar; nOutChars : Integer; lpMessage : PByte; nMsgLen : Integer; lpKey : PByte; nKeyLen : Integer; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function HMAC_HexFromHex(szOutput : PAnsiChar; nOutChars : Integer; szMsgHex : AnsiString; szKeyHex : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // BASE64 AND HEX CONVERSION FUNCTIONS
   function CNV_B64StrFromBytes(szOutput : PAnsiChar; nOutChars : Integer; input : PByte; nbytes : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CNV_BytesFromB64Str(output : PByte; out_len : Integer; input : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function CNV_B64Filter(szOutput : PAnsiChar; input : AnsiString; len : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CNV_HexStrFromBytes(szOutput : PAnsiChar; nOutChars : Integer; input : PByte; nbytes : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function CNV_BytesFromHexStr(output : PByte; out_len : Integer; input : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function CNV_HexFilter(szOutput : PAnsiChar; input : AnsiString; len : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   // UTF-8 CONVERSION/CHECK FUNCTIONS
   function CNV_UTF8FromLatin1(szOutput : PAnsiChar; nOutChars : Integer; szInput : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function CNV_Latin1FromUTF8(szOutput : PAnsiChar; nOutChars : Integer; szInput : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function CNV_CheckUTF8(szInput : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   
   // PEM/BINARY FILE CONVERSIONS
   function PEM_FileFromBinFile(szOutputFile : AnsiString; szFileIn : AnsiString; szHeader : AnsiString; nLineLen : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PEM_FileToBinFile(szOutputFile : AnsiString; szFileIn : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   
   // RNG FUNCTIONS
   function RNG_Bytes(lpOutput : PByte; nOutputLen : Integer; lpSeed : PByte; nSeedLen : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RNG_Number(nLower : Integer; nUpper : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RNG_BytesWithPrompt(lpOutput : PByte; nOutputLen : Integer; szPrompt : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RNG_Initialize(szSeedFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RNG_MakeSeedFile(szSeedFile : AnsiString; szPrompt : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RNG_UpdateSeedFile(szSeedFile : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function RNG_Test(szFileName : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   
   // MISC UTILITIES
   function WIPE_File(szFileName : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function WIPE_Data(lpData : PByte; nDataLen : Integer) : Integer; stdcall; external 'diCrPKI.dll';
   function PWD_Prompt(szPassword : PAnsiChar; nPwdLen : Integer; szCaption : AnsiString) : Integer; stdcall; external 'diCrPKI.dll';
   function PWD_PromptEx(szPassword : PAnsiChar; nPwdLen : Integer; szCaption : AnsiString; szPrompt : AnsiString; nOptions : Integer) : Integer; stdcall; external 'diCrPKI.dll';

const
  // GENERAL CONSTANTS
  PKI_DIR_ENCRYPT = 1;
  PKI_DIR_DECRYPT = 0;
  // Synonyms for direction
  ENCRYPT = 1;
  DECRYPT = 0;
  // Maximum number of bytes in hash digest byte array
  PKI_MAX_HASH_BYTES =64;
  PKI_SHA1_BYTES = 20;
  PKI_SHA224_BYTES = 28;
  PKI_SHA256_BYTES = 32;
  PKI_SHA384_BYTES = 48;
  PKI_SHA512_BYTES = 64;
  PKI_MD5_BYTES = 16;
  PKI_MD2_BYTES = 16;
  // Maximum number of hex characters in hash digest (excl null)
  PKI_MAX_HASH_CHARS =(2*PKI_MAX_HASH_BYTES);
  PKI_SHA1_CHARS = (2*PKI_SHA1_BYTES);
  PKI_SHA224_CHARS = (2*PKI_SHA224_BYTES);
  PKI_SHA256_CHARS = (2*PKI_SHA256_BYTES);
  PKI_SHA384_CHARS = (2*PKI_SHA384_BYTES);
  PKI_SHA512_CHARS = (2*PKI_SHA512_BYTES);
  PKI_MD5_CHARS = (2*PKI_MD5_BYTES);
  PKI_MD2_CHARS = (2*PKI_MD2_BYTES);
  // Synonym retained for backwards compatibility
  PKI_MAX_HASH_LEN = PKI_MAX_HASH_CHARS;
  // Encryption block sizes in bytes
  PKI_BLK_TDEA_BYTES =8;
  PKI_BLK_AES_BYTES = 16;
  // Key size in bytes
  PKI_KEYSIZE_TDEA_BYTES =24;
  PKI_KEYSIZE_MAX_BYTES = 32;
  // Required size for RNG seed file
  PKI_RNG_SEED_BYTES =64;

  // OPTION FLAGS
  PKI_DEFAULT = 0;
  // Signature algorithms
  PKI_SIG_SHA1RSA = 0;
  PKI_SIG_MD5RSA = 1;
  PKI_SIG_MD2RSA = 2;
  PKI_SIG_SHA256RSA =3;
  PKI_SIG_SHA384RSA =4;
  PKI_SIG_SHA512RSA =5;
  PKI_SIG_SHA224RSA =6;
  // PKCS#5 Password-based encryption algorithms
  PKI_PBE_SHA_3DES = 0;
  PKI_PBE_MD5_DES = 1;
  PKI_PBE_MD2_DES = 2;
  PKI_PBE_SHA_DES = 3;
  // --4 Deprecated option PKI_PBES2_3DES
  PKI_PBE_PBES2 = $1000;
  // Message digest hash algorithms
  PKI_HASH_SHA1 = 0;
  PKI_HASH_MD5 = 1;
  PKI_HASH_MD2 = 2;
  PKI_HASH_SHA256 = 3;
  PKI_HASH_SHA384 = 4;
  PKI_HASH_SHA512 = 5;
  PKI_HASH_SHA224 = 6;
  PKI_HASH_MODE_TEXT = $10000;
  // nFermatExp values for RSA exponent
  PKI_RSAEXP_EQ_3 = 0;
  PKI_RSAEXP_EQ_5 = 1;
  PKI_RSAEXP_EQ_17 = 2;
  PKI_RSAEXP_EQ_257 = 3;
  PKI_RSAEXP_EQ_65537 =4;
  // Return values for RSA_CheckKey
  PKI_VALID_PUBLICKEY = 1;
  PKI_VALID_PRIVATEKEY =0;
  // RSA key generation
  PKI_KEYGEN_INDICATE = $1000000;
  PKI_KEY_FORMAT_PEM = $10000;
  PKI_KEY_FORMAT_SSL = $20000;
  PKI_PFX_NO_PRIVKEY = $10;

  PKI_CMS_FORMAT_BASE64 = $10000;
  PKI_CMS_EXCLUDE_CERTS = $0100;
  PKI_CMS_EXCLUDE_DATA = $0200;
  PKI_CMS_INCLUDE_ATTRS = $0800;
  PKI_CMS_ADD_SIGNTIME = $1000;
  PKI_CMS_ADD_SMIMECAP = $2000;
  PKI_CMS_CERTS_ONLY = $0400;
  PKI_CMS_NO_OUTER = $2000000;
  PKI_CMS_ALT_ALGID = $4000000;

  PKI_XML_RSAKEYVALUE = $0001;
  PKI_XML_EXCLPRIVATE = $0010;
  PKI_XML_HEXBINARY = $0100;

  PKI_EME_DEFAULT = $00;
  PKI_EME_PKCSV1_5 = $00;
  PKI_EME_OAEP = $10;
  PKI_EMSIG_DEFAULT = $20;
  PKI_EMSIG_PKCSV1_5 = $20;
  PKI_EMSIG_DIGESTONLY = $1000;
  PKI_EMSIG_DIGINFO = $2000;
  PKI_EMSIG_ISO9796 = $100000;

  // Option flags
  PKI_X509_FORMAT_PEM = $10000;
  PKI_X509_FORMAT_BIN = $20000;
  PKI_X509_REQ_KLUDGE = $100000;
  PKI_X509_LATIN1 = $400000;
  PKI_X509_UTF8 = $800000;
  PKI_X509_AUTHKEYID = $1000000;
  PKI_X509_NO_BASIC = $2000000;
  PKI_X509_CA_TRUE = $4000000;
  PKI_X509_VERSION1 = $8000000;
  // Flags for Key Usage
  PKI_X509_KEYUSAGE_DIGITALSIGNATURE = $0001;
  PKI_X509_KEYUSAGE_NONREPUDIATION = $0002;
  PKI_X509_KEYUSAGE_KEYENCIPHERMENT = $0004;
  PKI_X509_KEYUSAGE_DATAENCIPHERMENT = $0008;
  PKI_X509_KEYUSAGE_KEYAGREEMENT = $0010;
  PKI_X509_KEYUSAGE_KEYCERTSIGN = $0020;
  PKI_X509_KEYUSAGE_CRLSIGN = $0040;
  PKI_X509_KEYUSAGE_ENCIPHERONLY = $0080;
  PKI_X509_KEYUSAGE_DECIPHERONLY = $0100;
  // Specific return values
  PKI_X509_EXPIRED = -1;
  PKI_X509_VALID_NOW = 0;
  PKI_X509_VERIFY_SUCCESS = 0;
  PKI_X509_VERIFY_FAILURE =-1;

  // Return values for CNV_CheckUTF
  PKI_CHRS_NOT_UTF8 = 0;
  PKI_CHRS_ALL_ASCII = 1;
  PKI_CHRS_ANSI8 = 2;
  PKI_CHRS_MULTIBYTE = 3;

  // Flags and return values for X.509 and CMS query functions
  PKI_QUERY_GETTYPE = $100000;
  PKI_QUERY_NUMBER = 1;
  PKI_QUERY_STRING = 2;

  // Options for RNG functions
  PKI_RNG_STRENGTH_112 = $00;
  PKI_RNG_STRENGTH_128 = $01;
  // Block cipher (BC) algorithm options
  PKI_BC_TDEA = $10;   // (
  PKI_BC_3DES = $10;   // ( equiv. synonyms for Triple DES
  PKI_BC_DESEDE3 =$10;   // (
  PKI_BC_AES128 = $20;
  PKI_BC_AES192 = $30;
  PKI_BC_AES256 = $40;
  // Block cipher mode options
  PKI_MODE_ECB = $000;
  PKI_MODE_CBC = $100;
  PKI_MODE_OFB = $200;
  PKI_MODE_CFB = $300;
  PKI_MODE_CTR = $400;
  // Key transport algorithms
  PKI_KT_RSAES_PKCS = $0000;
  // --$1000L Reserved for PKI_KT_RSAES_OEAP
  // --$2000L Reserved for PKI_KT_RSA_KEM
  // Key derivation functions
  PKI_KDF_KDF2 = $000;
  // --$300L Reserved for PKI_KDF_KDF3
  // General
  PKI_GEN_PLATFORM =$40;
00111100001100110010000001000100011001010110110001 1100000110100001101001
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#9

AW: Problem mit PAnsiChar und Rückgabewert einer Funktion CryptoSys PKI

  Alt 7. Sep 2015, 14:59
Macht ja nix, wenn der Autor keine Ahnung hat wird es dadurch nicht besser oder richtiger.

Die Infos auf der Seite lassen die Vermutung zu, dass diese Units von irgendwoher genommen wurden ohne Anspruch auf Korrektheit. Selbst Emba schafft es nicht die Windows-API korrekt zu übersetzen und nehmen sich dort eine gewisse künstlerische Freiheit raus (so wie es gerade gepasst hat).
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz