读书人

Metro施用存储数据方法

发布时间: 2012-11-25 11:44:31 作者: rapoo

Metro应用存储数据方法

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;        },

读书人网 >Web前端

热点推荐