encrypt- decrypt with SHA256 using java

20.7k views Asked by At

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

4

There are 4 answers

0
Mike Akers On BEST ANSWER

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.

0
yfeldblum On

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.

1
Sean A.O. Harney On

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

0
caf On

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.