Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不能正确处理空白符(空格、回车符等) #2

Closed
cblk opened this issue Dec 16, 2019 · 4 comments · Fixed by #3
Closed

不能正确处理空白符(空格、回车符等) #2

cblk opened this issue Dec 16, 2019 · 4 comments · Fixed by #3
Assignees
Labels
bug 和想象中样子有出入

Comments

@cblk
Copy link

cblk commented Dec 16, 2019

问题描述
当输入包含whitespace时,得到的结果和openssl(1.1.1d 10 Sep 2019)不同

复现
执行如下代码:

<?php
/**
 * demo @ sm3-php
 *
 * Code BY ch4o5
 * 10月. 12th 2019
 * Powered by PhpStorm
 */

require 'vendor/autoload.php';

$sm3 = sm3("a a");
echo $sm3;

结果:
1076807302544460b26944d7756a067bd4e135e2076889e86d62db5b5a10c867

对比openssl
执行:
 openssl dgst -sm3 test.txt
结果:
SM3(test.txt)= d6ef141c5faa9bbde67cbc9f45988d6158eaf0bc2ab492bb489a6524ca492cbc

对比在线工具
另一个在线工具的例子(http://aks.jd.com/tools/sec/):
深度截图_选择区域_20191216172917

环境 :

  • OS: Manjaro 18.1.4 Juhraya
  • Kernel: x86_64 Linux 4.19.88-1-MANJARO
  • PHP 7.4.0 (cli) (built: Nov 30 2019 10:43:49) ( NTS )
  • ch4o5/sm3-php: 1.1
@DongyunLee
Copy link
Owner

感谢反馈!
会尝试在即将到来的小版本中修复

@DongyunLee DongyunLee self-assigned this Jul 5, 2020
@DongyunLee DongyunLee added the bug 和想象中样子有出入 label Jul 5, 2020
@DongyunLee DongyunLee pinned this issue Jul 5, 2020
@DongyunLee
Copy link
Owner

空格问题已于1.1.1版本修复。确实是由于进行了过滤。

关于待处理字符串中出现换行的说明

值得一提的是,由于算法是按位的,所以在处理不同系统中的换行时,需要区分 LF/CR/CRLF
针对这三种系统中的换行,计算出来的值也是不同的。如:

[
    ["a\na"=>'c413edbaa5449ada676857e243ae8d66401d82474cc68c243950178280bf7ae0'],
    ["a\ra"=>'75056f768d1ac970ef2faf58ae4be4666afc157e2cb87b9e08c526463bf787da'],
    ["a\r\na"=>'d1041bb570f8c65e26299159e41e21961d0ce4b79a285ee32c75c11eab0a2dd7']
]

其中,Linux(\n)下的值,与苍墨安全中的计算结果相同。

Windows(\r\n)下、OS X(\n)下和Classic Mac(\r)无对照结果,暂时未测试,欢迎反馈。

@cblk 再次感谢反馈!

DongyunLee added a commit that referenced this issue Jul 6, 2020
* 移除了配置文件
* 移除了\SM3\types\ASCII类
* 按照PSR-12重新整理了项目
@DongyunLee
Copy link
Owner

DongyunLee commented Jul 6, 2020

合并了pr #3 ,感谢贡献!
我再更新个1.1.2的小版本,加上你的PR。

@DongyunLee DongyunLee reopened this Jul 6, 2020
@DongyunLee
Copy link
Owner

1.1.2已 发版,感谢贡献!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 和想象中样子有出入
Projects
None yet
2 participants