Encryption using SHA1

匆匆过客 提交于 2019-12-25 02:26:32

问题


I am developing a large application and i need encryption when a data is traveling between two machines in different continents. I have never worked on encryption. I want a simple encryption which can be handled in PHP / Ruby / Python without any dependencies.

So i decided to use HMAC SHA1.

$pad=hash_hmac("sha1","The quick brown....","mykey");

This is what i found out after some research on the internet.

How hard it is to decrypt it if someone doesn't know the key? Also, any alternatives to this?

UPDATE - thanks for all the responses. Problem solved.


回答1:


It's impossible to decrypt it, even if you know the key. HMAC SHA1 is a keyed hash algorithm, not encryption.

A hash is a cryptographic one-way function that always generates a value of the same length (I think SHA1 is 128-bits) regardless of the length of the input. The point of a hash is that, given the output value, it's computationally infeasible to find an input value to produce that output. A keyed hash is used to prevent rainbow table attacks. Even if you know the key you can't reverse the hash process.

For encryption you want to look at AES.




回答2:


SHA1 is a one-way-hash function, by definition it is not decryptable by anyone. The question becomes if you have a plaintext T that hashes to H. How hard is it to find another T which also hashes to H.

According to Wikipedia, for SHA1, the best known brute force attack would take 2^51 evlautions to find a plain text that matches.

If you need actual encryption where you can reverse the process, you should take a look at AES256.

See: http://en.wikipedia.org/wiki/Cryptographic_hash_function

For a general discussion on this.




回答3:


Like Andrew said SHA1 is an hash algorithm and cannot be used for encryption (since you cannot get back the original value). The digest it produce can be used to validate the integrity of the data.

An HMAC is a construct above an hash algorithm that accept a key. However it's not for meant for encryption (again it can't be decrypted) but it allows you to sign the data, i.e. with the same key you'll be able to ensure the data was not tampered with during it's transfer.

Foe encryption you should look at using AES or, if applicable to your application, HTTPS (which will deal with more issues than you want to know about ;-)




回答4:


SHA-1 , MD-5 are all one way Hashing algorithms. They just generate a lengthy string. Each and every string when subjected to these functions will yield you a lengthy string which cannot be retained back.

They are far from encryptions.

If you are looking for encryption algorithms , go for AES (Advanced Encryption Standard) , DES (Data Encryption Standard) Algorithms.




回答5:


As I say, this is a hash, so not an encryption/decryption problem. If you want to implement a straightforward encryption algorithm, I would recommend looking into XOR encryption. If the key is long enough (longer than the message) and your key sharing policy is suitably secure, this is a one time pad; otherwise, it can potentially be broken using statistical analysis.



来源:https://stackoverflow.com/questions/8929357/encryption-using-sha1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!