eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingZaszyfrowane CAPICOMem, jak odszyfrować CryptoAPI? › Zaszyfrowane CAPICOMem, jak odszyfrować CryptoAPI?
  • Path: news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!ipartners.pl!news2.ipartne
    rs.pl!not-for-mail
    From: "gosmo" <t...@m...pl>
    Newsgroups: pl.comp.programming
    Subject: Zaszyfrowane CAPICOMem, jak odszyfrować CryptoAPI?
    Date: Tue, 8 Sep 2009 14:26:35 +0200
    Organization: GTS Energis
    Lines: 62
    Message-ID: <h85ihs$1tj4$1@news2.ipartners.pl>
    NNTP-Posting-Host: 194.0.167.4
    X-Trace: news2.ipartners.pl 1252412796 63076 194.0.167.4 (8 Sep 2009 12:26:36 GMT)
    X-Complaints-To: a...@i...pl
    NNTP-Posting-Date: 8 Sep 2009 12:26:36 GMT
    X-Priority: 3
    X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
    X-RFC2646: Format=Flowed; Original
    X-Newsreader: Microsoft Outlook Express 6.00.2900.5843
    X-MSMail-Priority: Normal
    Xref: news-archive.icm.edu.pl pl.comp.programming:183425
    [ ukryj nagłówki ]

    Witam, mam zaszyfrowane dane poniższym kodem:
    EncryptedData := CreateOleObject('CAPICOM.EncryptedData');
    try
    EncryptedData.Algorithm.KeyLength :=
    CAPICOM_ENCRYPTION_KEY_LENGTH_40_BITS;
    EncryptedData.Algorithm.Name := CAPICOM_ENCRYPTION_ALGORITHM_3DES;
    EncryptedData.Content := AString;
    EncryptedData.SetSecret(ASecret);
    Result := EncryptedData.Encrypt;
    finally
    EncryptedData := Null;
    end;

    Aby odszyfrować to za pomocą CryptoAPI wykombinowałem takiego potworka:

    function DecodeWC(AString: WideString; ASecret: WideString = ''):
    WideString;
    var
    hProv : Cardinal;
    hHash : Cardinal;
    hKey : Cardinal;
    dwBlobLen : Cardinal;
    pBuffer : PByte;
    begin
    if (not CryptAcquireContext(hProv, Nil, NIL, PROV_RSA_FULL,
    CRYPT_VERIFYCONTEXT)) and (not CryptAcquireContext(hProv, Nil, Nil,
    PROV_RSA_FULL, CRYPT_VERIFYCONTEXT OR CRYPT_NEWKEYSET)) then
    RaiseLastOSError
    else
    try
    if not CryptCreateHash(hProv, CALG_MD5, 0, 0, hHash) then
    RaiseLastOSError
    else
    try
    if not CryptHashData(hHash, PByte(@ASecret[1]), Length(ASecret) * 2,
    0) then RaiseLastOSError;
    if not CryptDeriveKey(hProv, CALG_3DES, hHash, 0, hKey) then
    RaiseLastOSError
    else
    try

    dwBlobLen := Length(AString) * 2;
    pBuffer := PByte(@AString[1]);
    if not CryptDecrypt(hKey, 0, True, 0, pBuffer, dwBlobLen) then
    RaiseLastOSError;
    finally
    CryptDestroyKey(hKey);
    end;
    finally
    CryptDestroyHash(hHash);
    end;
    finally
    CryptReleaseContext(hProv, 0);
    end;
    end;

    Ale mimo, że używałem chyba wszystkich możliwych algorytmów hashujących to
    nadal dostaję komunikat złych danych przy CryptDecrypt.
    Jak odszyftować te dane za pomocą CryptoAPI?



Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: