标题:VFP系统下如何实现 AES-128加密
取消只看楼主
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
结帖率:40%
已结贴  问题点数:20 回复次数:9 
VFP系统下如何实现 AES-128加密
例如:
加密原文为【{"type":"fail","error":"E10006","error_description":"无返回结果!"}】,
秘钥为【123456】,
加密结果为
60EB8DF5E2BF4A9965B04202F703D6F1518B86A8D5FC417ADBC27C5E7BB7A6DA744B1C51DF975EA16125AB53502A437C4121C60A2A3348D4E3A11C558E13A3EF2BD1257869222C72CE9632EFF6D1BDE7

求高手指点
搜索更多相关主题的帖子: 加密 结果 type 系统 VFP 
2021-06-03 14:17
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
LOCAL lcPlainText
SET LIBRARY TO (LOCFILE("vfpencryption71.fll","FLL"))
m.lcPlainText = STRCONV("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710",16)
*!* F.1 ECB Example Vectors
*!* F.1.1 ECB-AES128.Encrypt
m.lcKey = "2b7e151628aed2a6abf7158809cf4f3c"
m.lcCiphertext = "3ad77bb40d7a3660a89ecaf32466ef97f5d3d58503b9699de785895a96fdbaaf43b1cd7f598ece23881b00e3ed0306887b0c785e27e8ad3f8223207104725dd4"
?IIF(Encrypt(m.lcPlainText, STRCONV(m.lcKey,16), 0, 0, 0, 16, 16) == STRCONV(m.lcCiphertext,16), "PASSED!", "FAILED!")
*!* F.1.2 ECB-AES128.Decrypt
?IIF(Decrypt(STRCONV(m.lcCiphertext,16), STRCONV(m.lcKey,16), 0, 0, 0, 16, 16) == m.lcPlainText, "PASSED!", "FAILED!")
SET LIBRARY TO

这个是从网上找的一个关于用 vfpencryption71.fll 来处理的方法,自带的样例在VFP 9.0下通过,但我的实例没好用,请高手指教!!!
2021-06-03 15:32
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
加密算法采用常见的对称加密算法AES(Advanced Encryption Standard),加密模式为ECB,填充方式为PKCS5Padding,输出结果要将byte[]字节转为Hex十六进制大写字符串(注意不要转成BASE64)

加密原文为【{"type":"fail","error":"E10006","error_description":"无返回结果!"}】,
秘钥为【1234567890123456】,
加密结果为1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC981826A61A97DF2AB7F875216A6DDDCECA176EC8A6959D79D6F77E8E3B4F3329

http://tool.

2021-06-03 17:25
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
4楼为最终确认的,之前的描述不足,请大家看4楼这个。
2021-06-03 17:26
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
正确的加密结果为:加密结果为1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC981826A61A97DF2AB7F875216A6DDDCECA176EC8A6959D79D6F77E8E3B4F3329

?STRCONV(Encrypt('{"type":"fail","error":"E10006","error_description":"无返回结果!"}','1234567890123456',0,0,0,16,16),15)
这组的加密结果为:
1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC3ECC615D03576CAB342FB3D5CA4C4F39AE410DCBD360510C0583C13C7EDA80C4
这组加密串解密后为:
{"type":"fail","error":"E10006","error_description":"

后面的汉字部分加密时好像是有问题
2021-06-03 17:46
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
将加密原文 {"type":"fail","error":"E10006","error_description":"无返回结果!"} 改为 {"type":"fail","error":"E10006","error_description":"No results returned"}
?STRCONV(Encrypt('{"type":"fail","error":"E10006","error_description":"No results returned"}','1234567890123456',0,0,0,16,16),15)
这组的加密结果为:
1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC15FAF84EDCF586E2EDA8F18C0D0E4E13E55C7F80C5EF45CDF55E43171B1E701F
这组加密串解密后为:{"type":"fail","error":"E10006","error_description":"No results returned"}

“无返回结果” 和 “!”带上均不正常,是不是字符集方面还需要进行相关处理呢》?
2021-06-03 17:56
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
十分感谢 radiofan  的回复!!!

SET LIBRARY TO myfll.fll ADDITIVE
SET LIBRARY TO vfpencryption71.fll ADDITIVE
lcPlainText = '{"type":"fail","error":"E10006","error_description":"无返回结果!"}'
lcCiphertext = ""
lcKey = "1234567890123456"
lcCiphertext = STRCONV(Encrypt(lcPlainText,lcKey,0,0,0,16,16),15)
?Decrypt(STRCONV(lcCiphertext,16),lcKey, 0, 0, 0, 16, 16)
SET LIBRARY TO
VFP中这组的加密结果为:
1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC3ECC615D03576CAB342FB3D5CA4C4F39AE410DCBD360510C0583C13C7EDA80C4
VFP环境下解密回去, 也是原文,这个没有问题。

但用在线校验工具(http://tool.)测试   {"type":"fail","error":"E10006","error_description":"无返回结果!"}
加密结果为1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC981826A61A97DF2AB7F875216A6DDDCECA176EC8A6959D79D6F77E8E3B4F3329
二者差异在 中文部分。
2021-06-04 15:46
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
SET LIBRARY TO myfll.fll ADDITIVE
SET LIBRARY TO vfpencryption71.fll ADDITIVE
lcPlainText = STRCONV('{"type":"fail","error":"E10006","error_description":"无返回结果!"}',9)   && DBCS转为utf-8
lcCiphertext = ""
lcKey = "1234567890123456"
lcCiphertext = STRCONV(Encrypt(lcPlainText,lcKey,0,0,0,16,16),15)
?STRCONV(Decrypt(STRCONV(lcCiphertext,16),lcKey, 0, 0, 0, 16, 16),11)    && utf-8转为DBCS
SET LIBRARY TO

这次虽然加密串与在线工具还是有点差异,但解密结果一致了。
十分感谢大家的关注与指导!
2021-06-04 17:04
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
LOCAL lcPlainText
SET LIBRARY TO (LOCFILE("vfpencryption71.fll","FLL"))
***例如: 加密原文为【{"type":"fail","error":"E10006","error_description":"无返回结果!"}】,
***       秘钥为【1234567890123456】,
***       加密结果为【1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC981826A61A97DF2AB7F875216A6DDDCECA176EC8A6959D79D6F77E8E3B4F3329】
m.lcKey = '1234567890123456'
m.lcPlainText ='{"type":"fail","error":"E10006","error_description":"无返回结果!"}'
****************************************  加密过程
tmp_sign=STRCONV(Encrypt(STRCONV(m.lcPlainText,9),m.lcKey ,0,0,2,16,16),15)
?tmp_sign
SET LIBRARY TO
************************************************************    以上处理加密后完全符合约定的加密结果。
但因要处理的加密内容较大,想将要加密的内容先存入 TXT 文本文件中,然后再读取到变量中,再进行加密处理,结果加密后的内容有偏差。

LOCAL lcPlainText
SET LIBRARY TO (LOCFILE("vfpencryption71.fll","FLL"))
***例如: 加密原文为【{"type":"fail","error":"E10006","error_description":"无返回结果!"}】,
***       秘钥为【1234567890123456】,
***       加密结果为【1CA3871BF40A3C5DE9F08BBBF693A9355B01760A57884D09E20F1BB5FB278BE90A4CE19F827F3A8DE7DD1D316BB814AC981826A61A97DF2AB7F875216A6DDDCECA176EC8A6959D79D6F77E8E3B4F3329】
m.lcKey = '1234567890123456'
&&&&&&   加密原文.txt  因要处理的内容较大,想保存于TXT文本文件中,然后再读取到变量中进行处理。
m.lcPlainText =(FileToStr("加密原文.txt"))

****************************************  加密过程
tmp_sign=STRCONV(Encrypt(STRCONV(m.lcPlainText,9),m.lcKey ,0,0,2,16,16),15)
?tmp_sign
SET LIBRARY TO

感觉是从TXT文件读取时与直接的变量有差异,但没找到处理方法,请高手指点!!
2022-07-23 14:53
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:37
专家分:14
注 册:2019-8-20
得分:0 
发完帖子,就找到原因了,应该是读取TXT文件时,字符集有变化了, 先转换下,再按加密规则进行就可以了。

****************************************  加密过程1
m.lcPlainText =(FileToStr("加密原文.txt"))
tmp_sign=STRCONV(Encrypt(STRCONV(STRCONV(m.lcPlainText,11),9),m.lcKey ,0,0,2,16,16),15)
2022-07-23 15:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505935-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.194582 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved