Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Add sample of backup rools, and handl AEADBadTagException (#540)
Browse files Browse the repository at this point in the history
* Add sample of backup rools, and handl AEADBadTagException

* Typos
  • Loading branch information
jamesmontemagno authored and Redth committed Oct 9, 2018
1 parent 8db259f commit 74aa962
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Samples/Samples.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/MainTheme"></application>
<application android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/MainTheme"
android:fullBackupContent="@xml/my_backup_rules">

</application>
</manifest>
5 changes: 5 additions & 0 deletions Samples/Samples.Android/Resources/xml/my_backup_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="${applicationId}.xamarinessentials.xml"/>
</full-backup-content>
5 changes: 5 additions & 0 deletions Samples/Samples.Android/Samples.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
<ItemGroup>
<AndroidAsset Include="Assets\FileSystemTemplate.txt" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\xml\my_backup_rules.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\..\CodeStyles.targets" />
</Project>
10 changes: 9 additions & 1 deletion Xamarin.Essentials/SecureStorage/SecureStorage.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ static Task<string> PlatformGetAsync(string key)
{
var encData = Convert.FromBase64String(encStr);
var ks = new AndroidKeyStore(context, Alias, AlwaysUseAsymmetricKeyStorage);
decryptedData = ks.Decrypt(encData);
try
{
decryptedData = ks.Decrypt(encData);
}
catch (AEADBadTagException)
{
System.Diagnostics.Debug.WriteLine($"Unable to decrypt key, {key}, which is likely due to an app uninstall. Removing old key and returning null.");
PlatformRemove(key);
}
}

return Task.FromResult(decryptedData);
Expand Down

0 comments on commit 74aa962

Please sign in to comment.