Hello,

Would anyone be able to point to a complete reference of the cryptoapi for 
FoxPro 9.0?
What I have so far is working (I think)until the CryptDeriveKey.

Thanks in advance for any ideas...

#include wincrypt.h
*
* decrypting section
*
CLEAR ALL
CLOSE ALL
CLEAR



DECLARE INTEGER CryptDestroyHash IN advapi32;
      INTEGER hHash

DECLARE INTEGER CryptReleaseContext IN advapi32;
      INTEGER hProvHandle,;
      INTEGER nReserved

tsFileName = GETFILE('enc')



= decrypt((tsFileName))


FUNCTION decrypt
      LPARAMETERS tsFileName
      hCryptProv = 0
      lhHashObject = 0
      lnDataSize = LEN(tsFileName)
      lcHashValue = REPLICATE(CHR(0), 8)
      lnHashSize = LEN(lcHashValue)

      DECLARE INTEGER CryptAcquireContextA ;
            IN WIN32API AS CryptAcquireContext ;
            INTEGER @lhProvHandle, ;
            STRING cContainer, ;
            STRING cProvider, ;
            INTEGER nProvType, ;
            INTEGER nFlags



*-=CryptAcquireContext( &hCryptProv, username, 0, dnPROV_RSA_FULL, 
dnCRYPT_NEWKEYSET )
      lnStatus = CryptAcquireContext(@hCryptProv, 0, 0, dnPROV_RSA_FULL, 
dnCRYPT_VERIFYCONTEXT)

*- hashing
      DECLARE INTEGER CryptCreateHash ;
            IN WIN32API AS CryptCreateHash ;
            INTEGER hProviderHandle, ;
            INTEGER nALG_ID, ;
            INTEGER hKeyhandle, ;
            INTEGER nFlags, ;
            INTEGER @hCryptHashHandle

      lnStatus = CryptCreateHash(hCryptProv, dnCALG_SHA, 0, 0, @lhHashObject )

      DECLARE INTEGER CryptHashData ;
            IN WIN32API AS CryptHashData ;
            INTEGER hHashHandle, ;
            STRING  @cData, ;
            INTEGER nDataLen, ;
            INTEGER nFlags

      lnStatus = CryptHashData( lhHashObject, tsFileName, lnDataSize, 0)

*//BYTE pbHash[1024];
//DWORD hashLen = 1024;
//CryptGetHashParam( hHash, HP_HASHVAL, pbHash, &hashLen, 0 );

*// set up RC2 key
      hKey  =     "jOsmwux8tIy1aN3Urq08"
*lnStatus = CryptDeriveKey(&hCryptProv, dnCALG_RC2, lhHashObject, 0x00800000, 
&hKey )
      lnStatus = CryptDeriveKey(&hCryptProv, dnCALG_RC2, lhHashObject, 0, &hKey 
)


iv = [8]
*iv[0] = iv[1] = iv[2] = iv[3] = iv[4] = iv[5] = iv[6] = iv[7] = 0

      =CryptSetKeyParam( hKey, KP_IV, iv, 0 )

*// now encrypt
      =CryptDecrypt( hKey, NULL, TRUE, 0, DATA, dataLen )

*// cleanup
      DECLARE INTEGER CryptDestroyHash IN advapi32;
            INTEGER hHash

      DECLARE INTEGER CryptReleaseContext IN advapi32;
            INTEGER hProvHandle,;
            INTEGER nReserved

      =CryptDestroyKey( hKey )
      =CryptDestroyHash( hHash )
      =CryptReleaseContext(hCryptProv,0)



ENDFUNC



--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/B6AD520020ACAE4188914E5A0DCE8AC4F1093A@MBX021-W3-CA-4.exch021.domain.local
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to