Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Chilkat activeX: decoding AND encoding AES-256 zip
Message
From
10/11/2020 11:18:43
 
 
To
10/11/2020 08:18:54
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01677081
Message ID:
01677091
Views:
71
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform