繁体   English   中英

毛伊岛的安全存储 - Android FileNotFoundException

[英]Secure Storage in Maui - Android FileNotFoundException

当我调用我的 Set 方法时,我得到 FileNotFound 异常。 我检查了文档但没有看到任何具体的实现(除了清单文件中的两个额外值)

这是我的代码

public async Task SetAsync(string key, string value)
{
  await SecureStorage.SetAsync(key, value);
}

这是 androidmanifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
    <application android:allowBackup="false" android:icon="@mipmap/appicon" android:exported="false" android:fullBackupContent="false" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

这里是例外

    [monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Security.SecurityCrypto.dll
Loaded assembly: /data/data/com.abc.mypp.test/files/.__override__/Xamarin.AndroidX.Security.SecurityCrypto.dll [External]
[AndroidKeysetManager] keyset not found, will generate a new one
[AndroidKeysetManager] java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_key_keyset__ does not exist
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readPref(SharedPrefKeysetReader.java:71)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readEncrypted(SharedPrefKeysetReader.java:89)
[AndroidKeysetManager]  at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:116)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:311)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
[AndroidKeysetManager]  at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:155)
[AndroidKeysetManager]  at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
[AndroidKeysetManager] keyset not found, will generate a new one
[AndroidKeysetManager] java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_value_keyset__ does not exist
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readPref(SharedPrefKeysetReader.java:71)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readEncrypted(SharedPrefKeysetReader.java:89)
[AndroidKeysetManager]  at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:116)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:311)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
[AndroidKeysetManager]  at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
[AndroidKeysetManager]  at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:160)
[AndroidKeysetManager]  at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
[EngineFactory] Provider GmsCore_OpenSSL not available

实际上,我已经创建了一个示例来测试 maui 中的Secure Storage 我调用了await SecureStorage.SetAsync(key, value); 在按钮的单击事件中,在模拟器 android 11、android 12 和物理设备小米 6X android 9 上运行。

它们都工作正常,密钥和值已写入设备。 所以可能有两个原因。

  1. 特殊设备:问题出现在特殊设备上,您可以尝试在其他设备或模拟器上运行项目。
  2. 一些参考版本:我在visual studio 17.4 preview 2.1上创建了项目,你可以升级visual studio并创建一个新项目来测试它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM