Prefs Editor
PrefsEditor.SecurePlayerPrefs Class Reference

A secured alternative to the PlayerPrefs class. More...

Public Types

enum  ItemType : byte { ItemType.None, ItemType.Int, ItemType.Float, ItemType.String }
 Enum for the different types of preferences an individual item can be. More...
 
enum  ItemMode : byte { ItemMode.XOR, ItemMode.AES }
 Mode of encryption for the specified item. More...
 

Static Public Member Functions

static bool HasKey (string key, bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static string EncryptKey (string key)
 Encrypt the key using simple Xor symmetric algorithm More...
 
static string DecryptKey (string key)
 Decrypt the key using simple Xor symmetric algorithm More...
 
static ItemType GetItemType (string encryptedString)
 For a secured entry, returns the type that it represents. Note that key should be the version saved in Player Prefs (Encrypted for secured prefs). More...
 
static void Save ()
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static void DeleteAll ()
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static void DeleteKey (string key, bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static float GetFloat (string key, float defaultValue=0.0f, bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static void SetFloat (string key, float value, bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static int GetInt (string key, int defaultValue=0, bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static void SetInt (string key, int value, bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static string GetString (string key, string defaultValue="", bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static void SetString (string key, string value, bool?useSecurePrefs=null)
 Wrapper for the same method in PlayerPrefs but works with encrypted player prefs. More...
 
static bool GetBool (string key, bool defaultValue=false, bool?useSecurePrefs=null)
 Get a boolean value from PlayerPrefs. More...
 
static void SetBool (string key, bool value, bool?useSecurePrefs=null)
 Set a boolean value in PlayerPrefs. More...
 
static void SetEncryptedPrefsEntry (string key, byte[] value, ItemType type)
 Set an encrypted prefs entry based upon the passed byte array and type More...
 
static string EncryptValue (byte[] value, ItemType type)
 Generate an encrypted string based upon the passed byte array and type More...
 
static string GetRawEncryptedPrefsEntry (string key)
 Get the raw encrypted prefs value for the given key More...
 
static byte[] GetDecryptedPrefsEntry (string key, ItemType type)
 Get and decrypt an encrypted prefs entry into a byte array. More...
 
static byte[] DecryptValue (string value, ItemType type)
 Check an encrypted string is in the correct format and decrypt the contained byte array More...
 
static string XorEncrypt (string value, string encryptionKey)
 Simple XOR based symmetric encryption of a value uses the passed key. More...
 
static string XorDecrypt (string value, string encryptionKey)
 Simple XOR based symmetric decryption of a value uses the passed key. More...
 
static byte[] XorEncryptDecrypt (byte[] value, string encryptionKey, int startIndex=0)
 Simple XOR based symmetric encryption and decryption of a value using the passed key. More...
 

Public Attributes

const string NotFoundString = "|[<not found>]|"
 A dummy string that can be used for encrypted entries to see if they are valid or not More...
 

Properties

static bool UseSecurePrefs [get, set]
 Flag indicating whether to use secure prefs. More...
 
static bool AutoConvertUnsecurePrefs [get, set]
 Flag indicating whether to use automatically convert unsecure prefs. More...
 
static string PassPhrase [get, set]
 The pass phrase that should be used. Be sure to override this with your own value. More...
 
static bool IsPassPhraseSet [get, set]
 Returns whether the pass phrase has been set. You should not rely on the default pass phrase value! More...
 

Detailed Description

A secured alternative to the PlayerPrefs class.

This class saves preferences values in an encrypted format.

Member Enumeration Documentation

Mode of encryption for the specified item.

TODO: AES is not currently supported.

Enumerator
XOR 
AES 

Enum for the different types of preferences an individual item can be.

Enumerator
None 
Int 
Float 
String 

Member Function Documentation

static string PrefsEditor.SecurePlayerPrefs.DecryptKey ( string  key)
static

Decrypt the key using simple Xor symmetric algorithm

Parameters
key
Returns
static byte [] PrefsEditor.SecurePlayerPrefs.DecryptValue ( string  value,
ItemType  type 
)
static

Check an encrypted string is in the correct format and decrypt the contained byte array

Parameters
value
type
Returns
byte array, or null if there was an error.
static void PrefsEditor.SecurePlayerPrefs.DeleteAll ( )
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static void PrefsEditor.SecurePlayerPrefs.DeleteKey ( string  key,
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static string PrefsEditor.SecurePlayerPrefs.EncryptKey ( string  key)
static

Encrypt the key using simple Xor symmetric algorithm

Parameters
key
Returns
static string PrefsEditor.SecurePlayerPrefs.EncryptValue ( byte[]  value,
ItemType  type 
)
static

Generate an encrypted string based upon the passed byte array and type

Parameters
value
type
Returns
static bool PrefsEditor.SecurePlayerPrefs.GetBool ( string  key,
bool  defaultValue = false,
bool?  useSecurePrefs = null 
)
static

Get a boolean value from PlayerPrefs.

static byte [] PrefsEditor.SecurePlayerPrefs.GetDecryptedPrefsEntry ( string  key,
ItemType  type 
)
static

Get and decrypt an encrypted prefs entry into a byte array.

Parameters
key
type
Returns
byte array, or null if there was an error.
static float PrefsEditor.SecurePlayerPrefs.GetFloat ( string  key,
float  defaultValue = 0.0f,
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static int PrefsEditor.SecurePlayerPrefs.GetInt ( string  key,
int  defaultValue = 0,
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static ItemType PrefsEditor.SecurePlayerPrefs.GetItemType ( string  encryptedString)
static

For a secured entry, returns the type that it represents. Note that key should be the version saved in Player Prefs (Encrypted for secured prefs).

Parameters
encryptedString
Returns
static string PrefsEditor.SecurePlayerPrefs.GetRawEncryptedPrefsEntry ( string  key)
static

Get the raw encrypted prefs value for the given key

Parameters
key
Returns
static string PrefsEditor.SecurePlayerPrefs.GetString ( string  key,
string  defaultValue = "",
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static bool PrefsEditor.SecurePlayerPrefs.HasKey ( string  key,
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static void PrefsEditor.SecurePlayerPrefs.Save ( )
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static void PrefsEditor.SecurePlayerPrefs.SetBool ( string  key,
bool  value,
bool?  useSecurePrefs = null 
)
static

Set a boolean value in PlayerPrefs.

static void PrefsEditor.SecurePlayerPrefs.SetEncryptedPrefsEntry ( string  key,
byte[]  value,
ItemType  type 
)
static

Set an encrypted prefs entry based upon the passed byte array and type

Parameters
key
value
type
static void PrefsEditor.SecurePlayerPrefs.SetFloat ( string  key,
float  value,
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static void PrefsEditor.SecurePlayerPrefs.SetInt ( string  key,
int  value,
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static void PrefsEditor.SecurePlayerPrefs.SetString ( string  key,
string  value,
bool?  useSecurePrefs = null 
)
static

Wrapper for the same method in PlayerPrefs but works with encrypted player prefs.

static string PrefsEditor.SecurePlayerPrefs.XorDecrypt ( string  value,
string  encryptionKey 
)
static

Simple XOR based symmetric decryption of a value uses the passed key.

static string PrefsEditor.SecurePlayerPrefs.XorEncrypt ( string  value,
string  encryptionKey 
)
static

Simple XOR based symmetric encryption of a value uses the passed key.

static byte [] PrefsEditor.SecurePlayerPrefs.XorEncryptDecrypt ( byte[]  value,
string  encryptionKey,
int  startIndex = 0 
)
static

Simple XOR based symmetric encryption and decryption of a value using the passed key.

Member Data Documentation

const string PrefsEditor.SecurePlayerPrefs.NotFoundString = "|[<not found>]|"

A dummy string that can be used for encrypted entries to see if they are valid or not

Property Documentation

bool PrefsEditor.SecurePlayerPrefs.AutoConvertUnsecurePrefs
staticgetset

Flag indicating whether to use automatically convert unsecure prefs.

If this is set then secure prefs that aren't found will automatically fall back and try to locate an unsecured version and then replace that with the secured alternative. This can be useful for existing games that make use of the standard player prefs.

bool PrefsEditor.SecurePlayerPrefs.IsPassPhraseSet
staticgetset

Returns whether the pass phrase has been set. You should not rely on the default pass phrase value!

string PrefsEditor.SecurePlayerPrefs.PassPhrase
staticgetset

The pass phrase that should be used. Be sure to override this with your own value.

bool PrefsEditor.SecurePlayerPrefs.UseSecurePrefs
staticgetset

Flag indicating whether to use secure prefs.

Note: at the current time all prefs used through this interface must adhere to this flag. The only way to mix secure and standard prefs is to mix calls with standard PlayerPrefs calls.


The documentation for this class was generated from the following file: