如何在Java中解密sha1加密的字符串 [英] How to decrypt sha1-encrypted String in Java

查看:1177
本文介绍了如何在Java中解密sha1加密的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

SHA1是否可以解密在Java中使用SHA-1算法加密的一些字符串? 加密散列函数,整个观点是您无法撤消它。如果可以反转哈希(找到给定哈希的输入),那将不会有用。如果您需要加密某些内容并稍后解密,则应使用加密功能,如 AES RSA



然而,对于非常简单的输入,可能破解哈希函数,猜测输入是什么,并检查哈希是否相同。



示例Python代码:

  def crack_hash(hash_to_crack,hash_function,list_of_guesses):
#尝试将我们的猜测列表中的所有内容
用于list_of_guesses中的猜测:
new_hash = hash_function(guess)
#如果哈希匹配,我们发现它
如果new_hash == hash_to_c机架:
返回猜猜
#如果没有匹配,放弃
返回无

当然,如果你真的想要有效地破解散列,使用像 John the Ripper Hashcat 可能是您最好的选择。请注意,这通常适用于密码,因为它们很简单,容易猜出,但随着输入增加,难度呈指数增长。您可以用分钟内的6个字符输入来破解每个SHA-1散列,而平均来说,打破16个字符的数字将需要数万亿年的时间。


Is it possible to decrypt some string which was earlier encrypted with the SHA-1 algorithm in Java?

解决方案

SHA1 is a cryptographic hash function, and the entire point is that you can't undo it. If it was possible to reverse the hash (find the input for a given hash), it wouldn't be useful. If you need to encrypt something and later decrypt it, you should use an encryption function like AES or RSA.

However, for very simple inputs it may be possible to crack the hash function by guessing what the input was and checking if the hash is the same.

Example Python code:

def crack_hash(hash_to_crack, hash_function, list_of_guesses):
    # Try to hash everything in our guess list
    for guess in list_of_guesses:
        new_hash = hash_function(guess)
        # if the hashes match, we found it
        if new_hash == hash_to_crack:
            return guess
    # If none of them match, give up
    return None

Of course, if you actually want to crack hashes efficiently, using software like John the Ripper or Hashcat is probably your best bet. Note that this usually works on passwords since they're short and easy to guess, but the difficulty increases exponentially as the input increases. You can crack every SHA-1 hash with a 6-character input in minutes, while cracking one with 16 characters would take trillions of years on average.

这篇关于如何在Java中解密sha1加密的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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