歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> OpenSSL下hash函數

OpenSSL下hash函數

日期:2017/2/28 14:30:24   编辑:Linux教程

OpenSSL下hash函數:是不可逆的函數,它的輸入可以是任意長度的字節流。它的輸出是固定大小的,hash函數的作用就是給你的文件產生一個摘要,它是獨一無二的。

OpenSSL TLS心跳讀遠程信息洩露漏洞 (CVE-2014-0160) http://www.linuxidc.com/Linux/2014-04/99741.htm

OpenSSL嚴重bug允許攻擊者讀取64k內存,Debian半小時修復 http://www.linuxidc.com/Linux/2014-04/99737.htm

OpenSSL “heartbleed” 的安全漏洞 http://www.linuxidc.com/Linux/2014-04/99706.htm

通過OpenSSL提供FTP+SSL/TLS認證功能,並實現安全數據傳輸 http://www.linuxidc.com/Linux/2013-05/84986.htm

例如:y=f(x) x代表輸入 y代表輸出 輸入x求y容易 單輸入y求x就難了

我們常見的hash函數MD5和SHA1 當然和有其他的比較少見。

DM5 :通常為128個bits  16個字節

sha1:通常為160bits 一個字節8個bits  20個字節

[root@RedHat ~]# md5sum /etc/passwd    //linux下也有命令來求文件md5的值
c79a0c2c792891374595009e6155435c /etc/passwd

[root@redhat ~]# openssl dgst -md5 /etc/passwd
MD5(/etc/passwd)= c79a0c2c792891374595009e6155435c

[root@redhat ~]# openssl dgst -sha1 /etc/passwd
SHA1(/etc/passwd)= b4e99419a91a3908e5e5c9c07a0d91c408c1a008

[root@redhat ~]# sha1sum /etc/passwd
b4e99419a91a3908e5e5c9c07a0d91c408c1a008 /etc/passwd

-c 參數 給輸出的hash值以:隔開

[root@redhat ~]# openssl dgst -sha1 -c /etc/passwd
SHA1(/etc/passwd)= b4:e9:94:19:a9:1a:39:08:e5:e5:c9:c0:7a:0d:91:c4:08:c1:a0:08

同樣也可以使用md5校驗文件的完整性,文件的一個字節變了,hash值就會發生天翻地覆的變化。

通常一些官方的網站把軟件包發布時都會發布MD5和sha1值,防止別人篡改軟件包。

[root@redhat opt]# cat txt
hello world!
[root@redhat opt]# md5sum txt
c897d1410af8f2c74fba11b1db511e9e txt

[root@redhat opt]# cat txt
hollo world!
[root@redhat opt]# md5sum txt
ada39606d10543a059d139d1debb6a37 txt

OpenSSL 的詳細介紹:請點這裡
OpenSSL 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved