save : function(key, value, callback) { var _usrBuffer; var _protectedUsr; var dataProtectionProvider = new Windows.Security.Cryptography.DataProtection.DataProtectionProvider('LOCAL=user'); _usrBuffer = Windows.Security.Cryptography.CryptographicBuffer.convertStringToBinary(value, Windows.Security.Cryptography.BinaryStringEncoding.utf8); var _usrPromise = dataProtectionProvider.protectAsync(_usrBuffer); _usrPromise.done(function (buffer) { _protectedUsr = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer); }, function (e) { var _e = e; }); WinJS.Promise.join([_usrPromise]).then(function () { var localSettings = Windows.Storage.ApplicationData.current.localSettings; localSettings.values[key] = _protectedUsr; if (callback) { callback(); } }); }, load: function(key,callback){ var localSettings = Windows.Storage.ApplicationData.current.localSettings; var _protectedUsr = localSettings.values[key]; console.log("_protectedUsr:" + _protectedUsr); if (!_protectedUsr) { return; } if (_protectedUsr.trim() == '') { return; } var _usrBuffer; var value; var dataProtectionProvider = new Windows.Security.Cryptography.DataProtection.DataProtectionProvider(); _usrBuffer = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(_protectedUsr); var _usrPromise = dataProtectionProvider.unprotectAsync(_usrBuffer); _usrPromise.done(function (buffer) { value = Windows.Security.Cryptography.CryptographicBuffer.convertBinaryToString(Windows.Security.Cryptography.BinaryStringEncoding.utf8, buffer); }, function (e) { var _e = e; }); var object; WinJS.Promise.join([_usrPromise]).done(function () { if (callback) { callback(value); } }); return object; },
Metro应用存储数据方法
最新推荐文章于 2023-08-14 09:44:40 发布