I'm creating an algorithm to hash some text variables (20/30 characters long) to send them across an insecure channel. I'm not dealing with high security data, so no credits card numbers or any other very sensitive information.

The original text variable is composed like this:


Then that is hashed and sent across the channel. However, the public random code is sent raw in the channel, so an attacker will know it. Does this make my hashing vulnerable to an attacker considering that the random code is about 30% of the whole variable? (I can change this if needed.)

  • 2
    $\begingroup$ What is your objective? Your objective is likely not creating an algorithm to hash some text variables, since that objective is directly met by applying SHA-1 or SHA-256. If your objective is limited to send text over an insecure channel, there's nothing to prevent you from doing that. We are left guessing that your objective likely is ensuring the origin, or/and protecting the integrity, or/and the confidentiality, of some of the text sent, by mean of hashing. Also we do not know what we can assume the sender and receiver initially have as key material. $\endgroup$
    – fgrieu
    Commented Oct 6, 2013 at 10:05
  • $\begingroup$ It depends on how long and random the secret and public data are. Looks like password hashing to me and if the channel is insecure you might want to consider other options. I agree with fgrieu's comment. $\endgroup$
    – rath
    Commented Oct 6, 2013 at 23:21

1 Answer 1


It's probably a really bad idea to try and roll-your-own here. If you have to ask a question like this, you would probably just be better off using shrink-wrapped solution like SSL rather than trying to make your own protocol. There are a lot of tricky problems around getting these kinds of things right.

However, if you insist on doing this yourself, there are constructions that allow you to do what you want to achieve here.

What you want is a message authentication code (MAC). You can MAC the hash of the variables and then send this across the insecure channel.

In order to do this safely, you need to use a construction like HMAC. You should particularly use such a construction if you are using SHA-1/SHA-256 as they suffer from message extension attacks.

You also need to guard against replays; that is, where an attacker resends a previously seen message on the channel with the hope of repeating an action or causing some other nefarious effect.

These are just a flavour of the kind of bear-traps that can spring when trying to design your own protocol!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.