PlayerPrefs - hashed string value problem

Hi, I tried to hash my values in Unity 5 with SHA256 algorithm. It works really well, but when I save it into PlayerPrefs and load it, it is not the same value. I think this is problem with PlayerPrefs, but I’m not sure. That is why I would like to ask you what is a problem? Is it a problem with special chars in PlayerPrefs? I would like to know how to fix it. Thanks in advance…

using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.Security.Cryptography;

public static class Zabezpiecznia {
	
	public static string SecureValue(int liczba) {
		byte[] tekstWejsciowy = Encoding.UTF8.GetBytes(liczba.ToString());
		HashAlgorithm hash = new SHA256Managed();
		byte[] zaszyfrowanaWiadomosc = hash.ComputeHash(tekstWejsciowy);
		return Encoding.Default.GetString(zaszyfrowanaWiadomosc);
	}
	
	public static string SecureValue(string tekst) {
		byte[] tekstWejsciowy = Encoding.UTF8.GetBytes(tekst);
		HashAlgorithm hash = new SHA256Managed();
		byte[] zaszyfrowanaWiadomosc = hash.ComputeHash(tekstWejsciowy);
		return Encoding.Default.GetString(zaszyfrowanaWiadomosc);
	}
	
	public static void SaveSafe(string nazwa, int wartosc)
	{
		PlayerPrefs.SetInt(nazwa,wartosc);
		PlayerPrefs.SetString(Zabezpiecznia.SecureValue(nazwa+"JB"),Zabezpiecznia.SecureValue(wartosc));
	}
	
	public static int LoadSafe(string nazwa, int wartoscDomyslna)
	{
		int tmpWartosc = PlayerPrefs.GetInt(nazwa,wartoscDomyslna);
		if (Zabezpiecznia.SecureValue(tmpWartosc) == PlayerPrefs.GetString(Zabezpiecznia.SecureValue(nazwa+"JB"),"ERROR"))
			return tmpWartosc;
		else
			return wartoscDomyslna;
	}
}

The problem might have to do with encoding arbitrary byte values as a string. If some of those values are, for example, the ASCII control characters between 0 and 31, nasty things could happen depending on how those are interpreted by the string reader or parser. For example, if one of the bytes is 0, it would be interpreted as ‘\0’, and the string writer or reader might assume the string is null-terminated and stop there even though the string is not finished yet. Another could be the value 8 (‘\b’ aka backspace) actually deleting the previous character in some contexts but not others.

The solution is to use System.Convert.ToBase64String to encode the byte array (and System.Convert.FromBase64String to go from a string back to a byte array). Base64 is a system specifically designed for storing arbitrary byte values safely as alphanumeric characters in instances like this.