在python中用(密码)解密SHA1 [英] Decrypt SHA1 with (password) in python

查看:3141
本文介绍了在python中用(密码)解密SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 hashlib 可以在Python中使用SHA-1加密功能。我使用这个哈希文件加密内容。



如果我为加密的文本文件设置了密码,我可以使用此密码进行解密并将文件恢复为原始文本?

解决方案

散列函数与普通加密算法不同。它们通常被称为单向密码,因为过程数据经过是不可逆转的。



与对称和非对称加密不同,散列值通过断言哈希值而不是解密和断言纯文本值。要在使用哈希值时验证登录名,您可以将用户刚刚尝试登录的密码进行哈希,并将其与数据库中的哈希进行比较。如果匹配,登录成功。



破解散列涉及猜测散列各种不同的字符串,并尝试将散列值与从DB非法获取的值相匹配。互联网上有列出数百万已经散列值的列表,使哈希破解变得更简单,这些列表被称为彩虹表,并且可以轻松地使用值得注意的是,由于散列算法能够将GB的数据消化到更小的字符串中,在数学上,两个不同的值可能具有相同的散列。即使这是非常罕见的,它是一个现有的问题,它被称为哈希碰撞



如果散列是可逆的,你可以想象一下吗?硬盘驱动器将会很简单,因为我们可以将数千个GB串入一小串文本,并按照我们的喜好进行反转。这将是数据压缩和存储的 nirvana





相关维基百科文章:



哈希算法: http:// en。维基百科,自由的百科全书noreferrer> http://en.wikipedia.org/wiki/Rainbow_table



盐: http://en.wikipedia.org/wiki/Salt_(加密)



碰撞: http://en.wikipedia.org/wiki/Collision_(computer_science)



对称加密: http:// en.wikipedia.org/wiki/Symmetric-key_algorithm



Assymetric加密: http://en.wikipedia.org/wiki/Public-key_cryptography


I have a function for encrypting with SHA-1 in Python, using hashlib. I take a file and encrypt the contents with this hash.

If I set a password for an encrypted text file can I use this password to decrypt and to restore the file with the original text?

解决方案

Hashing functions are different than normal crypto algorithms. They are oftenly referred to as one-way ciphers, because the process data goes through is irreversible.

Differently than symmetric and assymetric encryption, hashes are used by asserting the hashed values themselves, instead of decrypting and asserting the plain-text values. To validate logins when you're using hashes, you'd hash the password the user just attempted to log in with and compare it with the hash you have on your DB. If they match, login is successful.

Cracking hashes involves guessing hashing various different strings and trying to match hashed values to the ones illegally obtained from a DB. There are lists available on the internet with millions of already hashed values to make hash cracking easier, those are known as Rainbow Tables and they can be easily countered with the use of Salts.

It's also worth noting that since hashing algorithms are able to digest GBs of data into significantly smaller strings, mathematically, two different values may have identical hashes. Even though this is very rare, it is an existing problem, and its known as Hash Collision.

Can you immagine if hashing was reversible? Hard drives would be reduntant since we would be able to hash thousands of GBs into a small string of text and reverse them as we pleased. It would be the nirvana of data compression and storage.


Related Wikipedia Articles:

Hashing Algorithms: http://en.wikipedia.org/wiki/Hash_function

Rainbow Tables: http://en.wikipedia.org/wiki/Rainbow_table

Salts: http://en.wikipedia.org/wiki/Salt_(cryptography)

Collision: http://en.wikipedia.org/wiki/Collision_(computer_science)

Symmetric Encryption: http://en.wikipedia.org/wiki/Symmetric-key_algorithm

Assymetric Encryption: http://en.wikipedia.org/wiki/Public-key_cryptography

这篇关于在python中用(密码)解密SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆