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

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

问题描述

是否可以解密一些早期用Java中的SHA-1算法加密的字符串?

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

推荐答案

a 加密哈希函数,整个问题是你无法撤消它。如果可以反转哈希(找到给定哈希的输入),它将不会有用。如果您需要加密某项内容,然后解密,则应使用加密功能,例如 AES RSA

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.

示例Python代码:

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

当然,如果你真的想要有效地破解哈希,使用软件像约翰·Ripper 或< a href =https://hashcat.net/oclhashcat/ =nofollow> Hashcat 可能是你最好的选择。注意,这通常适用于密码,因为它们很短,容易猜中,但难度随着输入增加而呈指数增长。你可以在几分钟内用6个字符的输入来破解每个SHA-1哈希值,而破解16个字符的哈希值则平均需要数万亿年。

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.

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

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