2016-09-07 7 views
1

私はWindows 10を使用しています& Visual Studio 2015は、Android、iOS、Windows Phone、Windows Universalの開発とターゲティングに使用しています。XLabs.PlatformがUWPで動作しない

私はXLabs SecureStorage Serviceを使いたかったです。

私はXLabs.Platformパッケージ2.3.0-pre02を使用しています。

ファイル名:System.Runtime.WindowsRuntime、バージョン= 4.0私は(唯一のUWPのための)例外

secureStorage.Store(key, Encoding.UTF8.GetBytes(value)); 

を取得していますし、例外の詳細があり、このラインで

.11.0、文化=ニュートラル、PublicKeyToken = b77a5c561934e089

HRESULT:-2146234304

HELPLINK:ヌル

のInnerException:ヌル

メッセージ:ファイルまたはアセンブリをロードできませんでした「System.Runtime.WindowsRuntime、バージョン= 4.0.11.0、 Culture = neutral、PublicKeyToken = b77a5c561934e089 'またはその依存関係の1つ。見つかったアセンブリのマニフェスト定義がアセンブリ参照と一致しません。 (HRESULTからの例外:0x80131040)

出典:XLabs.Platform.UWP

SourceTrack:XLabs.Platform.Services.SecureStorage.d__6.MoveNextで()System.Runtime.CompilerServicesで 。いくつかの試行錯誤の後UWPTest.SecureStorageService.Store(String key, String value, Boolean overwrite)

+0

XLabsまだ進行中の巨大な作品です。それはUWPになるとさらにそうです。おそらく、UWPのために手動で実装する必要があります。 –

+0

Github経由でサンプルを共有することができればうれしいです。そうすれば、実際の問題を簡単に把握することができます。 –

答えて

1

XLabs.Platform.Services.SecureStorage.Store(String key, Byte[] dataBytes) でAsyncVoidMethodBuilder.StartTStateMachine iはXamarin UWPで正常にSecureStorageサービスを実行することができています。

SecureStorage.cs(コード)

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace ABC.UWP.Common 
{ 
    using System; 
    using System.IO; 
    using Windows.Storage; 
    using System.Threading; 
    using System.Runtime.InteropServices.WindowsRuntime; 
    using XLabs.Platform.Services; 
    using Windows.Security.Cryptography.DataProtection; 

    /// <summary> 
    /// Implements <see cref="ISecureStorage"/> for WP using <see cref="IsolatedStorageFile"/> and <see cref="ProtectedData"/>. 
    /// </summary> 
    public class SecureStorage : ISecureStorage 
    { 
     private static Windows.Storage.ApplicationData AppStorage { get { return ApplicationData.Current; } } 

     private static Windows.Security.Cryptography.DataProtection.DataProtectionProvider _dataProtectionProvider = new DataProtectionProvider(); 

     private readonly byte[] _optionalEntropy; 

     /// <summary> 
     /// Initializes a new instance of <see cref="SecureStorage"/>. 
     /// </summary> 
     /// <param name="optionalEntropy">Optional password for additional entropy to make encyption more complex.</param> 
     public SecureStorage(byte[] optionalEntropy) 
     { 
      this._optionalEntropy = optionalEntropy; 
     } 

     /// <summary> 
     /// Initializes a new instance of <see cref="SecureStorage"/>. 
     /// </summary> 
     public SecureStorage() : this(null) 
     { 

     } 

     #region ISecureStorage Members 

     /// <summary> 
     /// Stores the specified key. 
     /// </summary> 
     /// <param name="key">The key.</param> 
     /// <param name="dataBytes">The data bytes.</param> 
     public async void Store(string key, byte[] dataBytes) 
     { 
      //var mutex = new Mutex(false, key); 
      using (var mutex = new Mutex(false, key)) 
      { 
       try 
       { 
        mutex.WaitOne(); 

        var buffer = dataBytes.AsBuffer(); 

        if (_optionalEntropy != null) 
        { 
         buffer = await _dataProtectionProvider.ProtectAsync(buffer); 
        } 

        var file = await AppStorage.LocalFolder.CreateFileAsync(key, CreationCollisionOption.ReplaceExisting); 

        await FileIO.WriteBufferAsync(file, buffer); 
       } 
       catch (Exception ex) 
       { 
        throw new Exception(string.Format("No entry found for key {0}.", key), ex); 
       } 
      } 
      //finally 
      //{ 
      // mutex.ReleaseMutex(); 
      //} 
     } 

     /// <summary> 
     /// Retrieves the specified key. 
     /// </summary> 
     /// <param name="key">The key.</param> 
     /// <returns>System.Byte[].</returns> 
     /// <exception cref="System.Exception"></exception> 
     public byte[] Retrieve(string key) 
     { 
      var mutex = new Mutex(false, key); 

      try 
      { 
       mutex.WaitOne(); 

       return Task.Run(async() => 
       { 
        var file = await AppStorage.LocalFolder.GetFileAsync(key); 
        var buffer = await FileIO.ReadBufferAsync(file); 
        if (_optionalEntropy != null) 
        { 
         buffer = _dataProtectionProvider.UnprotectAsync(buffer).GetResults(); 
        } 
        return buffer.ToArray(); 
       }).Result; 
      } 
      catch (Exception ex) 
      { 
       throw new Exception(string.Format("No entry found for key {0}.", key), ex); 
      } 
      finally 
      { 
       mutex.ReleaseMutex(); 
      } 
     } 

     /// <summary> 
     /// Deletes the specified key. 
     /// </summary> 
     /// <param name="key">The key.</param> 
     public void Delete(string key) 
     { 
      var mutex = new Mutex(false, key); 

      try 
      { 
       mutex.WaitOne(); 

       Task.Run(async() => 
       { 
        var file = await AppStorage.LocalFolder.GetFileAsync(key); 
        await file.DeleteAsync(); 
       }); 
      } 
      finally 
      { 
       mutex.ReleaseMutex(); 
      } 
     } 

     /// <summary> 
     /// Checks if the storage contains a key. 
     /// </summary> 
     /// <param name="key">The key to search.</param> 
     /// <returns>True if the storage has the key, otherwise false.  </returns> 
     public bool Contains(string key) 
     { 
      try 
      { 
       return Task.Run(async() => await AppStorage.LocalFolder.GetFileAsync(key)).Result.IsAvailable; 
      } 
      catch 
      { 
       return false; 
      } 
     } 
     #endregion 
    } 
} 
関連する問題