._safeget - macmcmeans/localDataStorage GitHub Wiki

localDataStorage.safeget( keyName, [user scramble key] )

This method restores the obfuscated value stored under keyName returning the original value and data type. (If an Object was stored then an Object would be returned.) A user scramble key is optional, but if one were used to _safeset the key, it must be supplied in order to retrieve the original value. When omitted, the global scramble key will be transparently used.

EXAMPLES:

  • localData._safeset( 'safeMemKey1', 123456 )   -->   'my obfuscated data'
  • localData._safeset( 'safeMemKey2', 'my secret scramble key' )   -->   .007
  • localData._safeset( 'safeMemKey3', 'BR549' )   -->   Sun Oct 24 2022 19:34:31 GMT-0500 (Eastern Standard Time)
  • localData._safeset( 'safeMemKey4', {'z':['10']} )   -->   true

Obviously, if you call safeget on an obfuscated key and supply the wrong scramble key then the returned value will be incorrect.

✨ The complement to this is _safeset.

🛢 The corresponding disk-based method is safeget.

📝 NOTE: There is nothing to prevent you from _safesetting a key and then, inadvertently or otherwise, retrieving the value with a method other than _safeget. For instance, calling _get on a key that was created using _safeset will simply return the obfuscated value (not the original protected value).