Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to fix cryptDecrypt() error
Message
De
17/12/2004 16:38:25
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
How to fix cryptDecrypt() error
Divers
Thread ID:
00970199
Message ID:
00970199
Vues:
85
To reproduce:

1. Copy _crypt.vcx, _crypt.vct, wincrypt.h files shipped
with VFP 7,8 or 9 beta to some directory.
2. Make _crypt class decryptstr method public
Run the code below.

Observed result:

Error in _CRYPTAPI.CRYPTDECRYPT
Error Severity 2 (= warning)
Error Facility 9 (= windows service programming interface)
Error 3 (= bad key)

Expected result: no error


Any idea how to fix this ?
SET TALK OFF
SET ECHO OFF

ocrypt = NEWOBJECT('_cryptapi', '_crypt.vcx' )
ocrypt.lDisplayLowLevelAPIErrors = .t.
ocrypt.lDisplayHighLevelAPIErrors = .t.

*ocrypt.cprovidername="Microsoft Enhanced Cryptographic Provider v1.0"
*ocrypt.init()

cModulus = SPACE(128)
cexponent = '03'

* create RSA PUBLICKEYBLOB structure
lcSignaturePublicKey = fromhex("06020000 00240000")+ ;
	  'RSA1' + ;
	  myNum2DWord(8*LEN(m.cModulus)/2)+ ;
	  myNum2DWord( VAL('0x'+cExponent))+ ;
	  m.cModulus

lhPublicKey = 0

IF !oCrypt.ImportPublicKey(lcSignaturePublicKey, @lhPublicKey)
  MESSAGEBOX('error importing')
  RETURN
  ENDIF

lcsignature = SPACE(128)
cres=ocrypt.decryptstr( lcSignature, lhPublickey, .t. )
RETURN


#DEFINE _HEX "123456789ABCDEF"
FUNCTION fromhex( tcHexString )
LOCAL i,lcString,lcChar,lcHi,lcLo, ustr
tchexstring = CHRTRAN(tchexstring ,' ','')
lcString=""
FOR i=1 TO LEN(tcHexString) STEP 2
	lcString=lcString+CHR((AT(SUBSTR(tcHexString,i,1),_HEX)*16)+ ;
	                       AT(SUBSTR(tcHexString,i+1,1),_HEX))
ENDFOR
RETURN lcString

FUNCTION mynum2dword(lnValue)
IF lnValue < 0
 lnValue = 0x100000000 + lnValue
 ENDIF
LOCAL b0, b1, b2, b3
b3 = Int(lnValue/2^24)
b2 = Int((lnValue - b3*2^24)/2^16)
b1 = Int((lnValue - b3*2^24 - b2*2^16)/2^8)
b0 = Mod(lnValue, 2^8)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
ENDFUNC
Andrus
Répondre
Fil
Voir

Click here to load this message in the networking platform