Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Released] SecurePlayerPrefs

Discussion in 'Assets and Asset Store' started by burnner, Apr 21, 2015.

  1. burnner

    burnner

    Joined:
    Mar 2, 2013
    Posts:
    52


    Easily encrypt your serialized classes and PlayerPrefs!
    Replaces PlayerPrefs with an encrypted implementation.



    Features:
    - Easy to use!
    - Supports serialized classes!
    - Tight and very short code.
    - Works also on mobile!
    - Only two scripts!


    Output



    Demoscript
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using SecPlayerPrefs;
    5.  
    6. public class SecurePlayerPrefsDemo : MonoBehaviour {
    7.  
    8.     void Start () {
    9.  
    10.         //Write
    11.         SecurePlayerPrefs.SetFloat("float", 0.1f);
    12.         SecurePlayerPrefs.SetBool("bool", true);
    13.         SecurePlayerPrefs.SetInt("int", 100);
    14.         SecurePlayerPrefs.SetString("string", "amazing!");
    15.  
    16.         //Read
    17.         Debug.Log(SecurePlayerPrefs.GetFloat("float"));
    18.         Debug.Log(SecurePlayerPrefs.GetBool("bool"));
    19.         Debug.Log(SecurePlayerPrefs.GetInt("int"));
    20.         Debug.Log(SecurePlayerPrefs.GetString("string"));
    21.  
    22.         //Serialized Classes
    23.         //Write
    24.         SecureplayerPrefsDemoClass c = new SecureplayerPrefsDemoClass();
    25.         SecureDataManager<SecureplayerPrefsDemoClass> dataManager = new SecureDataManager<SecureplayerPrefsDemoClass>("name");
    26.         c.incremental = true;
    27.         c.playID = "tester";
    28.         c.type = 10;
    29.         dataManager.Save(c);
    30.  
    31.         //Read
    32.         SecureDataManager<SecureplayerPrefsDemoClass> dataManagerReader =
    33.     new SecureDataManager<SecureplayerPrefsDemoClass>("name");
    34.         c = dataManagerReader.Get();
    35.         Debug.Log(c.incremental);
    36.         Debug.Log(c.type);
    37.         Debug.Log(c.playID);
    38.  
    39.     }
    40. }
    41.  
    42. using System;
    43.  
    44. [Serializable()]//Important
    45. public class SecureplayerPrefsDemoClass
    46. {
    47.     public string playID { get; set; }
    48.     public int type { get; set; }
    49.     public bool incremental { get; set; }
    50.  
    51.     public SecureplayerPrefsDemoClass()
    52.     {
    53.         this.playID = "";
    54.         this.type = 0;
    55.         this.incremental = false;
    56.     }
    57. }
    58.  

     
    Last edited: Apr 30, 2015
  2. burnner

    burnner

    Joined:
    Mar 2, 2013
    Posts:
    52
    SecurePlayerPrefs has been accepted at the Asset store!
     
  3. burnner

    burnner

    Joined:
    Mar 2, 2013
    Posts:
    52
    Free voucher: gonna
     
    Last edited: May 3, 2015
  4. hytka81

    hytka81

    Joined:
    Jun 22, 2013
    Posts:
    27
    Hi!

    Thanks for SecurePlayerPrefs. I was wondering if there is a reason for not to have default values for the Set methods like PlayerPrefs has?

    I made that change myself but it would be nice if it was included if I you release an updated version.

    Another question. Should this work also on Android?

    Br,

    Kalle
     
    Last edited: Oct 28, 2015
  5. burnner

    burnner

    Joined:
    Mar 2, 2013
    Posts:
    52
    Hi what do you mean with defaul values? Can you show me this?

    Sure this works on every platform I guess. I personally use it for Android
     
  6. hytka81

    hytka81

    Joined:
    Jun 22, 2013
    Posts:
    27
    Hi!

    Sorry, I made a mistake by talking about Set methods, I meant Get methods instead.

    By default values I mean override or optional second parameter for each Get method to allow setting default value if Key does not exist. PlayerPrefs has, for example, PlayerPrefs.GetString("Keyname", "default"); which will return "default" if key does not exist.

    This was easy to implement but I'm not sure if that was the reason SecurePlayerPrefs didn't seem to work on Android device... My game starts normally but after that Get or Set does not work and I get some exception or error somewhere (didn't do any debuggin yet). When I reverted back to regular PlayerPrefs it worked again.

    EDIT: Now that I have debugged the crash more it is not caused by SecurePlayerPrefs, it seems I failed miserably with my first implementation of default parameters for Get methods. Now it is working nicely also on my Android device :)

    Br,

    Kalle
     
    Last edited: Oct 29, 2015