views:

1458

answers:

4

Hi guys.

Please help me the code (Java) to encrypt and decrypt ( will be better if using private key) with SHA256. ^^

Thank you so much!

+5  A: 

The Secure Hash Algorithm family of functions are one-way functions. You can use the functions to get a cryptographic hash from any given input, but it is impossible to reverse the function and arrive at the input from any given output hash.

Justice
+2  A: 

SHA-256 is a one way algorithm, it cannot be decrypted!

Sean A.O. Harney
+4  A: 

I think you're confused about what SHA is. SHA is a Cryptographic Hash Function, not an encryption algorithm. You can't reverse the operation to determine the message that was used to generate a particular hash.

Mike Akers
+4  A: 

There have actually been several techniques proposed for turning hash functions into block ciphers that can encrypt and decrypt - for example Peter Gutmann's "Message Digest Cipher".

This paper has some cryptanalysis of some of these techniques.

But you really don't want to do this - you are far better off using a well-studied block cipher, like AES.

caf
+1 for suggesting an appropriate alternative
Bruce Alderman