linux shell 下 HMAC-SHA1 实现

sun522198556 2013-09-03 06:22:56
这是php代码的实现 :

hash_hmac("sha1", "value", "key", TRUE);

这是php手册参数最后一个true解释
true : When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits.

这是shell 实现
echo -n "value" | openssl sha1 -hmac "key"

但是 没有转化为二进制

请问有什么方案和php输出的一样


感谢大神
...全文
714 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
糊涂的小白 2013-09-03
  • 打赏
  • 举报
回复
引用 1 楼 lisa5001 的回复:
openssl sha有个-binary的选项,是你说的二进制么。。
$] echo -n "value" | openssl sha1 -hmac "key"
57443a4c052350a44638835d64fd66822f813319
$] echo -n "value" | openssl sha1 -binary -hmac "key"
WD:L#P?F8?]d?f?/?3
$] echo -n "value" | openssl sha1 -binary -hmac "key"  | hexdump -Cv
00000000  57 44 3a 4c 05 23 50 a4  46 38 83 5d 64 fd 66 82  |WD:L.#P.F8.]d.f.|
00000010  2f 81 33 19                                       |/.3.|
00000014
糊涂的小白 2013-09-03
  • 打赏
  • 举报
回复
openssl sha有个-binary的选项,是你说的二进制么。。
1、查看SSH客户端版本 有的时候需要确认一下SSH客户端及其相应的版本号。使用ssh -V命令可以得到版本号。需要注意的是,Linux一般自带的是OpenSSH: 下面的例子即表明该系统正在使用OpenSSH: $ ssh -V OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003 下面的例子表明该系统正在使用SSH2: $ ssh -V ssh: SSH Secure Shell 3.2.9.1 (non-commercial version) on i686-pc-linux-gnu 2、用SSH登录到远程主机 当你第一次使用ssh登录远程主机时,会出现没有找到主机密钥的提示信息。输入"yes"后,系统会将远程主机的密钥加入到你的主目录下的 .ssh/hostkeys下,这样你就可以继续操作了。示例如下: 1 2 3 4 5 6 7 8 localhost$ ssh -l jsmith remotehost.example.com Host key not found from database. Key fingerprint: xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-jarde-tuxum You can get a public key‘s fingerprint by running % ssh-keygen -F publickey.pub on the keyfile. Are you sure you want to continue connecting (yes/no)? Yes Host key saved to /home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub host key for remotehost.example.com, accepted by jsmith Mon May 26 2008 16:06:50 -0700 jsmith@remotehost.example.com password: remotehost.example.com$ 因为远程主机的密钥已经加入到ssh客户端的已知主机列表中,当你第二次登陆远程主机时,只需要你输入远程主机的登录密码即可。 1 2 3 localhost$ ssh -l jsmith remotehost.example.com jsmith@remotehost.example.com password: remotehost.example.com$ 由于各种原因,可能在你第一次登陆远程主机后,该主机的密钥发生改变,你将会看到一些警告信息。出现这种情况,可能有两个原因: o 系统管理员在远程主机上升级或者重新安装了SSH服务器 o 有人在进行一些恶意行为,等等。 在你输入“yes”之前呢,最佳的选择或许是联系你的系统管理员来分析为什么会出现主机验证码改变的信息,核对主机验证码是否正确。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 localhost$ ssh -l jsmith remotehost.example.com @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the- middle attack)! It is also possible that the host key has just been changed. Please contact your system administrator. Add correct host key to ―/home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub‖ to get rid of this message. Received server key's fingerprint: xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-arde-tuxum You can get a publ

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧