0

I am building a security mechanism and I need a Pseudorandom functionality in my app. More particularly I need to convert a String to fix length.

My strings are random already, they just to long so I want to convert them to fix size. A trivial solution(the one that I am using now) will be just cut the extra characters, the problem with this approach that it reduce from the strength of my original random that I used to generate the string at the first place.

So I need some sort of method that will except an array of bytes and will give me new array of bytes, but it will be always the same output for given input.

And I dont want to use solutions like XOR or some other math, I want it to be psado random, and I will store the psado random key or data in local storage.

Any suggestions?

  • 2
    what you seem to be describing is a hash function – a method of deriving a fixed-size fingerprint of arbitrarily-sized input. However, you might encounter hash collisions where two strings have the same hash. You will also be limiting randomness to the hash size. Choosing an appropriate hash function can be difficult since most functions were designed as fast data integrity checks, not as storage for keys. – amon Oct 18 '15 at 8:12
  • @amon its fine, for my particular needs any hash algorithm will do, I just have some trouble to find one. – Ilya Gazman Oct 18 '15 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.