vendredi 26 juin 2015

Same random guarantee

I have got this code:

BigInteger bigInteger = new BigInteger(64, new Random());
Long longValue=-Math.abs(bigInteger.longValue());
int desiredLen=384;
Random random=new Random(longValue);
byte [] randomString=new byte[desiredLen];
for(int i=0;i<desiredLen;i++)
    randomString[i]=(byte)(Math.abs(random.nextInt())&255);

Now there are these values:

  • longValue - is sent to other side (server) and later used to generate key again on other side
  • randomString - is encryption key generated randomly based on longValue

Simply, client sends message containing first 8 bytes longValue and other stuff is encrypted content by randomString.

What is guarantee that numbers will be generated exactly same on all machines and virtual machines and all Java versions based on received longValue? And how about if client is written in other language like C#?




Aucun commentaire:

Enregistrer un commentaire