| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3149 人关注过本帖, 1 人收藏
标题:VFP系统下如何实现 AES-128加密
只看楼主 加入收藏
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:38
专家分:14
注 册:2019-8-20
结帖率:40%
收藏(1)
已结贴  问题点数:20 回复次数:14 
VFP系统下如何实现 AES-128加密
例如:
加密原文为【{"type":"fail","error":"E10006","error_description":"无返回结果!"}】,
秘钥为【123456】,
加密结果为
60EB8DF5E2BF4A9965B04202F703D6F1518B86A8D5FC417ADBC27C5E7BB7A6DA744B1C51DF975EA16125AB53502A437C4121C60A2A3348D4E3A11C558E13A3EF2BD1257869222C72CE9632EFF6D1BDE7

求高手指点
搜索更多相关主题的帖子: 加密 结果 type 系统 VFP 
2021-06-03 14:17
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:38
专家分: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
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
收藏
得分:20 
加密以后的字符串不是你给出的!
?Encrypt('{"type":"fail","error":"E10006","error_description":"无返回结果!"}','123456',0,0,0,6,0)

需要给出具体的转换规则?
2021-06-03 17:08
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:38
专家分: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
等 级:论坛游民
帖 子:38
专家分:14
注 册:2019-8-20
收藏
得分:0 
4楼为最终确认的,之前的描述不足,请大家看4楼这个。
2021-06-03 17:26
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:38
专家分: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
等 级:论坛游民
帖 子:38
专家分: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
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
收藏
得分:0 
汉字转换为单字节字符试试
2021-06-03 22:34
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
收藏
得分:0 
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

*************

SET LIBRARY TO myfll.fll ADDITIVE
SET LIBRARY TO vfpencryption71.fll ADDITIVE

lcPlainText = '{"type":"fail","error":"E10006","error_description":"无返回结果!"}'
lcCiphertext = ""
lcKey = "1234567890123456"

lcCiphertext = Encrypt(lcPlainText,lcKey,0,0,0,16,16)

?Decrypt(lcCiphertext,lcKey, 0, 0, 0, 16, 16)

SET LIBRARY TO

*******************

SET LIBRARY TO myfll.fll ADDITIVE
SET LIBRARY TO vfpencryption71.fll ADDITIVE

lcPlainText = '{"type":"fail","error":"E10006","error_description":"无返回结果!"}'
lcCiphertext = ""
lcKey = "1234567890123456"

lcCiphertext = Encrypt(lcPlainText,lcKey)

?Decrypt(lcCiphertext,lcKey)

SET LIBRARY TO

结果都一样,默认状态下,密码可以设置任意长度。你测试下!

[此贴子已经被作者于2021-6-4 09:34编辑过]

2021-06-04 09:21
lnfx2019
Rank: 2
等 级:论坛游民
帖 子:38
专家分: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
快速回复:VFP系统下如何实现 AES-128加密
数据加载中...
 
   



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

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