encryptionhashcryptographysha2

Hashing a string to a specific length


I have been tasked with getting a string to encrypted to a certain length. Ideally....the function should take as parameters...

  1. String to be encrypted of variable size
  2. the length of the resulting encrypted string

It does not need to be decrypted. I've been looking at SHA384, but I've been unable to understand the samples online to the point of modifying it to make it hash to a specified length.


Solution

  • You can't request the length, that is part of the method.

    If you want a shorter output just remove the extra bytes, each byte (and bit) is individually random, it makes no difference which bytes are removed.


    Hashing is not encryption, it is a one-way non-reversavble function that takes a variable amount of input and generates a fixed amount of output.

    Do you need encryption of a hash?