Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Chilkat activeX: decoding AND encoding AES-256 zip
Message
De
10/11/2020 14:38:43
 
 
À
10/11/2020 11:18:43
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01677081
Message ID:
01677094
Vues:
63
J'aime (1)
Daniel, I was more than glad to direct you to a quick pathway to Chilkat. There's lot of things to discover and use in VFP, providing the alignment with more recent systems and technologies (encryption, OAuth, TLS 1.3, just to name a few).

>Hi Antonio,
>
>I mixed things up a bit whilst building the "save" and "open" code snipets that were needed. But yep I found my way into the online Chilkat documentation, a great one! The code below seems to work fine. Ain't clean and in need of tydying. But it works:-)
>Code for building an AES256 encrypted zip file from arbitrary VFP string and user-defined password:
>
>LPARAMETERS cPassword AS MEMO
>
>IF EMPTY(M.cPassword)
>	cPassword = "myPassword"
>ENDIF
>
>LOCAL ckZip AS Chilkat_v9_5_0.ChilkatZip
>LOCAL ckUnzip AS Chilkat_v9_5_0.ChilkatZip
>LOCAL ckZipEntry AS Chilkat_v9_5_0.ChilkatZipEntry
>LOCAL MemZip AS Variant
>LOCAL MemUnzip AS String
>
>m.ckZip = CREATEOBJECT("Chilkat_9_5_0.Zip")
>
>*!*	* set encryption mode to AES
>m.ckZip.Encryption = 4
>*!*	* set key length
>m.ckZip.EncryptKeyLength = 256
>* and the key itself
>m.ckZip.EncryptPassword = cPassword
>
>* create a dummy Zip file
>IF m.ckZip.NewZip("c:/hroffice/dummy.zip") != 1
>	MESSAGEBOX(m.ckZip.LastErrorText)
>	RETURN
>ENDIF
>
>* add some data to the Zip object
>m.ckZip.AppendString2("entry.txt", "my AES protected string", "utf-8")
>
>* and write the object to memory
>m.MemZip = m.ckZip.WriteToMemory()
>
>** DG extra >> save the zip into the physical file resource 
>loFac = CREATEOBJECT("Chilkat_9_5_0.FileAccess")
>IF m.loFac.WriteEntireFile("test.zip",M.MemZip) <> 1
>	MESSAGEBOX(m.ckZip.LastErrorText)
>	RETURN
>ENDIF
>
>RETURN
>
>
>Code for feeding a VFP string from the AES-256 zipped resource:
>
>LPARAMETERS cPassword AS MEMO
>
>IF EMPTY(M.cPassword)
>	cPassword = "myPassword"
>ENDIF
>
>LOCAL ckZip AS Chilkat_v9_5_0.ChilkatZip
>LOCAL ckUnzip AS Chilkat_v9_5_0.ChilkatZip
>LOCAL ckZipEntry AS Chilkat_v9_5_0.ChilkatZipEntry
>LOCAL MemZip AS Variant
>LOCAL MemUnzip AS String
>
>m.ckUnzip = CREATEOBJECT("Chilkat_9_5_0.Zip")
>
>m.ckUnzip.Encryption = 4
>m.ckUnzip.EncryptKeyLength = 256
>m.ckUnzip.DecryptPassword = cPassword
>
>m.ckUnzip.OpenZip("test.zip")
>IF (m.ckUnzip.LastMethodSuccess=0)
>	RETURN
>ENDIF
>
>loEntry 	= m.ckUnzip.FirstMatchingEntry("entry.txt")
>lcStrCsv  = M.loEntry.UnzipToString(0,"utf-8")
>
>IF EMPTY(lcStrCsv)
>	MESSAGEBOX("password is incorrect!")
>ELSE	
>	MESSAGEBOX(lcStrCsv)
>ENDIF
>
>RETURN
>
>
>Thanks for feeding me with great startup material on this large, thus pretty intimidating, library. Looking forward to using more of the Chilkat suite!
>
>Regards, Daniel
----------------------------------
António Tavares Lopes
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform