Skip to content

SaveIntegrityUtility (en)

Guilherme Sena edited this page Dec 11, 2024 · 1 revision

This is a static class that provides the methods to shuffle and unshuffle bytes, and it can generates a SHA-256 hash.

public static List ShuffleBytes(List originalBytes, int seed)

  • originalBytes: Bytes list to shuffle.
  • seed: Seed to be used in the random number generator.

This method shuffle bytes in this way: It generates a shuffle order by GetOrder() method, returning a shuffled number list, then a for loop is created according to the bytes list length getting each byte position that was generated by shuffled numbers list and adding the bytes in an array. Then, returning a shuffled bytes list.

Example: We have the following text that would be our bytes: ABCDE and our generated order was: 3 2 0 1 4

The original position is:

A B C D E

0 1 2 3 4

Moving to another array in a shuffled way:

D C A B E

3 2 0 1 4

public static List<byte> UnshuffleBytes(List<byte> shuffledBytes, int seed)

  • shuffledBytes: Bytes list to unshuffle.
  • seed: Seed used in the random number generator.

This method unshuffles the bytes according to the seed used in the shuffling. If another seed is used, the unshuffling will return the wrong order.

public static string GetStringHash(string content, string salt)

  • content: Content to generate a hash.
  • salt: "Salt" to add in the content.

This method returns a hash of the content with a "salt", making the hash more unique and difficulting a hash injection.

private static List<int> GetOrder(int bytesSize, int seed)

  • bytesSize: List bytes size.
  • seed: Seed to be used in the random number generator.

This methods starts generating a possible numbers list based in the bytes amount, then it moves the generated position to a new numbers list through a while loop.

Clone this wiki locally