這是一個園長學習VFP(Visual Foxpro)的Blog歡迎同好一起來參與

星期二, 3月 16, 2010

VFP提供之加密類別(_cryptapi.vcx)研究

自從VFP提供了_cryptapi這個class後,就一直想找到時間來研究一下
因為VFP的資料庫保密性差,不論您程式寫的再好,需要保密的資料無法保密
也是徒然浪費時間吧
以下為測試的情況提供給各位參考

*請將本文複製到空的程式中另存prg執行(Test By GREEN)
oCrypto = Newobject("_cryptapi", Home(1) + "ffc_crypt.vcx") tcKey = "中文字可不可以啊?"
teststr="this is a test"
lcCipher=""
lcText=""
*加密
oCrypto.encryptSessionBlockString(teststr, tcKey, @lcCipher )
WAIT lcCipher+STR(LEN(lcCipher)) windows
*解密
oCrypto.decryptSessionBlockString(lcCipher, tcKey, @lcText)
WAIT lcText+STR(LEN(lcText)) windows
teststr="中文加密跟解密測試"
*加密
oCrypto.encryptSessionBlockString(teststr, tcKey, @lcCipher )
WAIT lcCipher+STR(LEN(lcCipher)) windows
*解密
oCrypto.decryptSessionBlockString(lcCipher, tcKey, @lcText)
WAIT lcText+STR(LEN(lcText)) windows
*中文相容測試
CREATE CURSOR testdb (tidx c(80))
SELECT testdb
wtidx=""
oCrypto.encryptSessionBlockString("中文字", tcKey, @wtidx)
INSERT INTO testdb VALUES (wtidx)
oCrypto.encryptSessionBlockString("英文字", tcKey, @wtidx)
INSERT INTO testdb VALUES (wtidx)
oCrypto.encryptSessionBlockString("This is a monkey", tcKey, @wtidx)
INSERT INTO testdb VALUES (wtidx)
oCrypto.encryptSessionBlockString("法文字", tcKey, @wtidx)
INSERT INTO testdb VALUES (wtidx)
BROWSE &&先看看
SELECT testdb
GO top
*測試 Locate
*先將要找的字編碼
serstr=""
*
oCrypto.encryptSessionBlockString("monkey", tcKey, @serstr)
WAIT serstr windows
LOCATE FOR serstr$tidx
IF FOUND()
WAIT "哇...找到了!!" windows &&結果-->找到了
ELSE
WAIT "不妙!!找不到耶" windows
ENDIF
*
oCrypto.encryptSessionBlockString("英文字", tcKey, @serstr)
WAIT serstr windows
LOCATE FOR serstr$tidx
IF FOUND()
WAIT "哇...找到了!!" windows &&結果-->找到了
ELSE
WAIT "不妙!!找不到耶" windows
ENDIF
*
serstr=""
oCrypto.encryptSessionBlockString("英文", tcKey, @serstr)
WAIT serstr windows
LOCATE FOR serstr$tidx
IF FOUND()
WAIT "哇...找到了!!" windows
ELSE
WAIT "不妙!!找不到耶" windows &&結果-->找不到
ENDIF
USE
*結論
*英文及中文皆可正常的加密跟解密
*因其編碼方式的關係,故 "This a Monkey"中的"Monkey" 與單獨一個字的"Monkey"的編碼會不同
*因此在做字串部分比對時會出現問題,提供給網友參考

發表於 2007/04/03 12:06 AM

沒有留言: