Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
I have an encrypted string (encoded with a key using HMACSHA256). Now how can I decrypt it back using the key and HMACSHA256 algorithm?
Posted

1 solution

The question make no sense at all. This is not encryption. And your string cannot be decrypted, because nothing was encrypted. I don't know what do you call a "key", but you don't have a key. Probably you have only the hash-based message authentication code, only HMAC value itself, which does not contains the string you thought you "encrypted". You did not. You never mentioned you had "encrypted data".

Please see:
http://en.wikipedia.org/wiki/Hash-based_message_authentication_code[^],
https://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacsha256%28v=vs.110%29.aspx[^].

To understand how something can be hash-based and what cryptographic hash does, please see:
http://en.wikipedia.org/wiki/Cryptographic_hash_function[^],
see also http://en.wikipedia.org/wiki/SHA-2[^].

—SA
 
Share this answer
 
v2
Comments
arunkx 25-Feb-15 0:42am    
I will explain the process in detail.

public string function(string data,string key)
{
System.Text.UTFEncoding encode=new UTFEncoding ();
byte [] kbyte=encode.GetBytes(key);
byte [] mbyte=encode.GetBytes(data);
HMACSHA256 hmac=new HMACSHA256(kbyte);
byte []hmsg=hmac.ComputeHash(mbyte);
string rslt=Convert.ToBase64String(hmsg,0,hmsg.length);
return rslt;
}


This is how I did my encryption. Now I have the encrypted text and the key. How can I decrypt it back?
Sergey Alexandrovich Kryukov 25-Feb-15 6:39am    
Are you serious? Do I have to repeat? You did not do encryption. There is nothing to decrypt.
—SA
arunkx 25-Feb-15 6:47am    
Sorry. Doing this for the first time :)
Sergey Alexandrovich Kryukov 25-Feb-15 6:48am    
No problem.
Will you accept the answer formally now? I think I explained everything.
—SA
arunkx 25-Feb-15 6:51am    
Before that, I have hashed some data here. Can you tell me how to retrieve the data back if I have the key?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900