 |
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
garfield Site Admin

註冊時間: 2003-01-30 文章: 2160
第 1 樓
|
發表於: 星期五 二月 26, 2010 2:44 pm 文章主題: 也算是針對檔案加密的方法 |
|
|
* ? '加密成功否:',secretfile('我的檔案.doc')
* ? '解密成功否:',secretfile('我的檔案.doc', .T.)
FUNCTION secretfile
LPARAMETERS mfile , unsecret
IF AT(["],mfile)=0
mfile=["]+mfile+["]
endif
IF !FILE(mfile)
WAIT windows '找不到檔案:'+mfile nowait
RETURN .f.
ENDIF
LOCAL mh, mstat, mlen, mled, mret
mled = '檔案已加密'
Mh = FOPEN(mfile,12)
IF mh<1
WAIT windows '無法開啟檔案'+mfile nowait
RETURN .f.
ENDIF
mret = .f.
LOCAL mfilelen,mdata
DO case
case !unsecret .and. mled <> FREAD(mh,10)
mlen = FLOOR(RAND(0)*256)
mfilelen = FSEEK(mh,0,2)
FSEEK(mh,0,0)
mdata = FREAD(mh,mfilelen) &&--請注意: 應該會有檔案長度限制
FSEEK(mh,0,0)
mstat = FWRITE(mh,mled+CHR(mlen)+PADR(mdata,mlen) + mdata)
* 本方法無法加密純文字檔, 研發人員: garfield
* 加密原理: 改掉檔頭, 讓一些相關程式無法開啟
* 會加長檔案長度 11+最多255字
IF mstat<1
WAIT windows '無法加密'+mfile nowait
ELSE
mret = .t.
ENDIF
case unsecret
mstat = FREAD(mh,10)
IF mstat <> mled
WAIT windows '非用本方式加密' nowait
else
mlen = ASC(FREAD(mh,1))
mfilelen = FSEEK(mh,0,2)
FSEEK(mh,0,0)
mdata = FREAD(mh, mfilelen) &&--請注意: 應該會有檔案長度限制
FSEEK(mh,0,0)
mstat = FWRITE(mh,SUBSTR(mdata,11+mlen+1))
IF mstat<1
WAIT windows '無法解密'+mfile nowait
ELSE
mret = .t.
ENDIF
endif
ENDcase
FCLOSE(mh)
RETURN mret _________________ 利用>>搜尋<<的功能會比問的還要快得到答案. |
|
回頂端 |
|
 |
goto-dream
註冊時間: 2004-05-11 文章: 909
第 2 樓
|
|
回頂端 |
|
 |
garfield Site Admin

註冊時間: 2003-01-30 文章: 2160
第 3 樓
|
發表於: 星期五 六月 25, 2010 7:05 pm 文章主題: |
|
|
1.直接用fopen() 來開檔, 不需要執行跟檔案相關的執行程式.
2.可以自行須改成另存新檔, 多幾行程式而已. _________________ 利用>>搜尋<<的功能會比問的還要快得到答案. |
|
回頂端 |
|
 |
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|