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 发布
本文介绍了一种利用Cryptography库保护和加载应用数据的方法,通过数据保护提供者实现本地用户数据的安全存储。
4391

被折叠的 条评论
为什么被折叠?



