sameerkapps / SecureStorage

119 stars 32 forks source link

Android FormatException when accessing a non existing value #46

Open Sebastian1989101 opened 5 years ago

Sebastian1989101 commented 5 years ago

When calling this code: Convert.ToBoolean(CrossSecureStorage.Current.GetValue(nameof(MyProperty), false.ToString()))

I got this exception:

[0:] AndroidEnvironment.UnhandledExceptionRaiser: System.FormatException: Invalid length for a Base-64 char array or string.
  at System.Convert.FromBase64_Decode (System.Char* startInputPtr, System.Int32 inputLength, System.Byte* startDestPtr, System.Int32 destLength) [0x001db] in <d4a23bbd2f544c30a48c44dd622ce09f>:0 
  at System.Convert.FromBase64CharPtr (System.Char* inputPtr, System.Int32 inputLength) [0x00031] in <d4a23bbd2f544c30a48c44dd622ce09f>:0 
  at System.Convert.FromBase64String (System.String s) [0x00025] in <d4a23bbd2f544c30a48c44dd622ce09f>:0 
  at Plugin.SecureStorage.AndroidKeyStoreImplementation.GetValue (System.String key, System.String defaultValue) [0x00036] in <32517fff446a4abfbff8b506c1031d3c>:0 
  at Plugin.SecureStorage.SecureStorageImplementation.GetValue (System.String key, System.String defaultValue) [0x00009] in <32517fff446a4abfbff8b506c1031d3c>:0 

Is there a way to prevent the exception on Android? It don't come up on iOS and I don't like the way to use try-catch all over the place in my getters.