Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #6024 > unrolled thread
| Started by | "Francesco F." <francescangeli.f.remove@remove.gmail.com> |
|---|---|
| First post | 2013-10-05 19:06 +0200 |
| Last post | 2013-10-15 08:33 +0200 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
Someone of you knows about CryptBinaryToString ? "Francesco F." <francescangeli.f.remove@remove.gmail.com> - 2013-10-05 19:06 +0200
Re: Someone of you knows about CryptBinaryToString ? Sherlock <sherlock@sherlock.com.au> - 2013-10-06 03:57 -0700
Re: Someone of you knows about CryptBinaryToString ? "Francesco F." <francescangeli.f.remove@remove.gmail.com> - 2013-10-06 14:50 +0200
Re: Someone of you knows about CryptBinaryToString ? Gustavo Biasone <rosario.soft@gmail.com> - 2013-10-14 09:35 -0700
Re: Someone of you knows about CryptBinaryToString ? "Francesco F." <francescangeli.f.remove@remove.gmail.com> - 2013-10-15 08:33 +0200
| From | "Francesco F." <francescangeli.f.remove@remove.gmail.com> |
|---|---|
| Date | 2013-10-05 19:06 +0200 |
| Subject | Someone of you knows about CryptBinaryToString ? |
| Message-ID | <l2pgup$a3n$1@news.albasani.net> |
I need help about a function in Crypto32.dll; I need to convert a
calculated MD5 in Hex form to MD% in base64 form, (22 chars, like
"xx4K6Mixq/dDUQORH2dLPQ==").
The ultimate goal is to send via WebService a file and its Hash in MD5
base64, as requested.
I'm struggling with CryptBinaryToString(), but it seems to be hard to me
to chew...
Basing on what found googleing for hours, I created a prototype:
_DLL FUNCTION CryptBinaryToString(pbBinary AS BYTE PTR, cbBinary AS
DWORD, dwFlags AS DWORD, pszString AS PSZ, pcchString AS PTR) AS DWORD
PASCAL:crypt32.CryptBinaryToStringA
and then, stealing up and down in NG I wrote this pearl: 8-))
--------------------------------------------------
FUNCTION BASE64(InputStr AS STRING) AS STRING
// InputStr = "C71E0AE8C8B1ABF7435103911F674B3D", an MD5 in Hex format
LOCAL cOutput AS STRING
LOCAL nbuffer AS DWORD
LOCAL nSize AS DWORD
LOCAL ptrByte AS BYTE PTR
LOCAL ptrWord AS WORD PTR
LOCAL waw AS DWORD
nSize := Len(InputStr)
ptrByte := MemAlloc(nSize)
FOR waw := 1 UPTO nSize
ptrByte[waw] := BYTE(_CAST, SubStr(InputStr, waw, 1))
NEXT
cOutput := PSZ(Space((nsize / 2) + 1))
nbuffer := 0
CryptBinaryToString(ptrByte, nSize, CRYPT_STRING_BASE64, cOutput, @nbuffer)
? nbuffer // here returns 0
MemFree(ptrByte)
RETURN cOutput
--------------------------------------------------
My doubt is about that nbuffer.
MS$ states:
BOOL WINAPI CryptBinaryToString(
_In_ const BYTE* pbBinary,
_In_ DWORD cbBinary,
_In_ DWORD dwFlags,
_Out_opt_ LPTSTR pszString,
_Inout_ DWORD* pcchString
)
and looks like DWORD* is a PTR.
Where am I wrong?
TIA for any help,
Francesco
[toc] | [next] | [standalone]
| From | Sherlock <sherlock@sherlock.com.au> |
|---|---|
| Date | 2013-10-06 03:57 -0700 |
| Message-ID | <417a2a3a-4984-47c3-bd37-c4c8b7199a1f@googlegroups.com> |
| In reply to | #6024 |
//---------------------------
FUNCTION RKF_MD5File ( cFile AS STRING ) AS STRING PASCAL
LOCAL cString AS STRING
LOCAL cRet AS STRING
cString:=Space(32)
MDFile(cFile,cString)
IF Instr("FILE NOT FOUND",cString)
cRet:=NULL_STRING
ELSE
cRet:= Upper(cString)
ENDIF
RETURN cRet
//---------------------------------
FUNCTION RKF_MD5String ( cString AS STRING ) AS STRING PASCAL
LOCAL cToReceive AS STRING
LOCAL liLenght AS LONG
cToReceive:=Space(SLen(cString))
liLenght:= LONG(_CAST,SLen(cString))
MDStringFix ( cString, liLenght ,cToReceive )
//
RETURN Upper(cToReceive)
//-----------------------------------
_DLL FUNCTION MDFile ( f AS STRING , r AS STRING) ;
AS VOID PASCAL:aamd532.MDFile
_DLL FUNCTION MDStringFix ( f AS STRING, t AS LONG , r AS STRING ) ;
AS VOID PASCAL:aamd532.MDStringFix
To download the AAMD532.DLL for MD5
http://www.skatendestroy.co.uk/download-a-dll/aamd532_dll-information.html
[toc] | [prev] | [next] | [standalone]
| From | "Francesco F." <francescangeli.f.remove@remove.gmail.com> |
|---|---|
| Date | 2013-10-06 14:50 +0200 |
| Message-ID | <l2rmbl$8gu$1@news.albasani.net> |
| In reply to | #6026 |
Hi Sherlock, thanks for answering.
I already know aamd532 library, really good one, and is just with it
that I calculate MD5 for my files.
The problem is that RKF_MD5File gives me a 32 chrs hex string, 16
bytes, like "C71E0AE8C8B1ABF7435103". So far so good, but I must send a
base64 string of length 22 chars.
I.e. "C71E0AE8C8B1ABF7435103" must become "xx4K6Mixq/dDUQORH2dLPQ=="
(real example)
I don't know how achieve that result.
I tried, and I'm keeping on try, with (translated from someone's PHP
function):
------------------------------------------------------------------
FUNCTION Base64Encode(StringMD5, howmany) // MD5 already calculated and
its length
LOCAL coutput AS STRING
LOCAL i AS DWORD
LOCAL nvalue AS DWORD
LOCAL itoa64 AS STRING
LOCAL waw AS DWORD
coutput := ""
i := 0
itoa64 :=
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
DO WHILE i < quanti
nvalue := Asc(CharPos(StringMD5, ++i))
coutput += CharPos(itoa64, _And(howmany, 63))
IF i < howmany
nvalue := _Or(nvalue, Asc(CharPos(StringMD5, i)) << 8)
ENDIF
coutput += CharPos(itoa64, _And((nvalue >> 6), 63))
IF ++i >= howmany
EXIT
ENDIF
IF i < howmany
nvalue := _Or(valore, Asc(CharPos(StringMD5, i)) << 16)
ENDIF
coutput += CharPos(itoa64, _And((nvalue >> 12), 63))
IF ++i >= howmany
EXIT
ENDIF
coutput += CharPos(itoa64, _And((nvalue >> 18), 63))
ENDDO
RETURN coutput
------------------------------------------------------------------
but the result is "akXkcsbjcsbl1DGn.cHn0zakYrqjW", definitely different
from what I expext...
I know somewhere exist a function Base64MD5 working the way I want, see
ChillKat's Crypt2.dll, but of course I can't extract that function 8-((.
Making use ov a VBScript like:
------------------------------------------------------------------
DIM fso, crypt, outFile
DIM Filename, Hashname
DIM success, hash, hash64
DIM base64
DIM fromEncoding, toEncoding
Set fso = CreateObject("Scripting.FileSystemObject")
Set crypt = CreateObject("Chilkat.Crypt2")
success =
crypt.UnlockComponent("ANWB-45Z9-WNVV-EMZZ-GDCE-T7JV-97LX-M6K4-EBV3-NZMM-YMUJ2J2")
IF (success <> 1) Then
WScript.Quit
END IF
Filename="C:\EuroAmerican\Professional\Clienti\FRANCESCANGELI FRANCESCO
- 130204102917\DOCUMENTI\condizioni generali.pdf"
Hashname="C:\EuroAmerican\Professional\Clienti\FRANCESCANGELI FRANCESCO
- 130204102917\DOCUMENTI\condizioni generali.pdf.MD5"
Set outFile = fso.CreateTextFile(Hashname, TRUE)
crypt.HashAlgorithm = "md5"
hash = crypt.HashFileENC(Filename)
outFile.WriteLine(hash)
outFile.Close
------------------------------------------------------------------
I get the correct result "xx4K6Mixq/dDUQORH2dLPQ=="... but, having
problems with Windows security alerts asking user for confirm everytime
i call the VBS, I'd prefer doing all calculations inside my app.
I hope I've been exhaustive in explicating my problem, and I hope too
someone can help me...
Thanks,
Francesco
Il 06/10/2013 12:57, Sherlock ha scritto:
> //---------------------------
> FUNCTION RKF_MD5File ( cFile AS STRING ) AS STRING PASCAL
> LOCAL cString AS STRING
> LOCAL cRet AS STRING
>
> cString:=Space(32)
> MDFile(cFile,cString)
> IF Instr("FILE NOT FOUND",cString)
> cRet:=NULL_STRING
> ELSE
> cRet:= Upper(cString)
> ENDIF
> RETURN cRet
> //---------------------------------
> FUNCTION RKF_MD5String ( cString AS STRING ) AS STRING PASCAL
>
> LOCAL cToReceive AS STRING
> LOCAL liLenght AS LONG
>
> cToReceive:=Space(SLen(cString))
> liLenght:= LONG(_CAST,SLen(cString))
>
> MDStringFix ( cString, liLenght ,cToReceive )
> //
> RETURN Upper(cToReceive)
>
> //-----------------------------------
> _DLL FUNCTION MDFile ( f AS STRING , r AS STRING) ;
> AS VOID PASCAL:aamd532.MDFile
>
> _DLL FUNCTION MDStringFix ( f AS STRING, t AS LONG , r AS STRING ) ;
> AS VOID PASCAL:aamd532.MDStringFix
>
> To download the AAMD532.DLL for MD5
> http://www.skatendestroy.co.uk/download-a-dll/aamd532_dll-information.html
>
[toc] | [prev] | [next] | [standalone]
| From | Gustavo Biasone <rosario.soft@gmail.com> |
|---|---|
| Date | 2013-10-14 09:35 -0700 |
| Message-ID | <3d1cc9bb-8024-418c-b760-0b191c0fe5e5@googlegroups.com> |
| In reply to | #6027 |
Hi Francesco, Not sure if I understand correctly your problem, but if you already have Crypt2.dll and it does the job you need, why don't you create the object (Chilkat.Crypt2) from whithin VO code instead of using a VB script. That way you won't get the security alerts popup. Regards, Gustavo Biasone
[toc] | [prev] | [next] | [standalone]
| From | "Francesco F." <francescangeli.f.remove@remove.gmail.com> |
|---|---|
| Date | 2013-10-15 08:33 +0200 |
| Message-ID | <l3inl1$pd1$1@news.albasani.net> |
| In reply to | #6091 |
Hi Gustavo, my original problem was to avoid registering the Ocx when installing my app on PC; I circumvented that need by registering it from inside app just when it starts; much less code to write... 8-)) Thanks for answering, Francesco Il 14/10/2013 18:35, Gustavo Biasone ha scritto: > Hi Francesco, > > Not sure if I understand correctly your problem, but if you already have Crypt2.dll and it does the job you need, why don't you create the object (Chilkat.Crypt2) from whithin VO code instead of using a VB script. That way you won't get the security alerts popup. > > Regards, > Gustavo Biasone >
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web