This is good, but now I don't know how to convert it back. If some one can help me eather with this example or suggest something else, how I can encode/decode a small string into a something longer, would be great.

1 Answer
1

You probably need to elaborate on how you are going to use it and why, as you have just opened Pandora's box :)

An encoding is reversible and should only be used to make data fit into something else (like base 64 binary data when you can only use text), a hash (like sha224) is not supposed to be reversible.

If you want to verify a user entering a password, you hash it (with like sha224) and store the hash, then when the user enters password again, you hash their entry and compare. This is the simplified version, you also need to add "salt" to avoid a simple "dictionary attack". I won't elaborate as that wasn't the question you asked.

To quickly answer your question you want an encryption library, like the cipher AES-128, which has a secret key and with the key you can recover the original data. There will be some details in the library on how to create the key (it has to be a specific length and will be manipulated to make it that length). If your key is based on simple passwords, go look at PBKDF2, which makes a strong encryption key from a weak password.

Don't confuse hmac as encryption (hmac uses another function, like the hashing function sha224), if the receiver of a messages shares a hmac key with the sender, they can "authenticate" that the message can from the sender, and it came without alteration.

Good luck!

P.S. here is a good book if you really want to start digging in:
Cryptography Engineering: Design Principles and Practical Applications