java 解密 sha,如何在Java中解密sha1加密的字符串

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值