@@ -27,10 +27,12 @@ class AndroidOptions extends Options {
2727 StorageCipherAlgorithm .AES_CBC_PKCS7Padding ,
2828 this .sharedPreferencesName,
2929 this .preferencesKeyPrefix,
30+ bool onlyAllowStrongBox = false ,
3031 }) : _encryptedSharedPreferences = encryptedSharedPreferences,
3132 _resetOnError = resetOnError,
3233 _keyCipherAlgorithm = keyCipherAlgorithm,
33- _storageCipherAlgorithm = storageCipherAlgorithm;
34+ _storageCipherAlgorithm = storageCipherAlgorithm,
35+ _onlyAllowStrongBox = onlyAllowStrongBox;
3436
3537 /// EncryptedSharedPrefences are only available on API 23 and greater
3638 final bool _encryptedSharedPreferences;
@@ -70,6 +72,12 @@ class AndroidOptions extends Options {
7072 /// WARNING: If you change this you can't retrieve already saved preferences.
7173 final String ? preferencesKeyPrefix;
7274
75+ /// If true, only allow keys to be stored in StrongBox backed keymaster.
76+ /// This option is only available on API 28 and greater. If set to true some phones might now work
77+ /// Defaults to false.
78+ /// https://developer.android.com/training/articles/keystore#HardwareSecurityModule
79+ final bool _onlyAllowStrongBox;
80+
7381 static const AndroidOptions defaultOptions = AndroidOptions ();
7482
7583 @override
@@ -80,6 +88,7 @@ class AndroidOptions extends Options {
8088 'storageCipherAlgorithm' : _storageCipherAlgorithm.name,
8189 'sharedPreferencesName' : sharedPreferencesName ?? '' ,
8290 'preferencesKeyPrefix' : preferencesKeyPrefix ?? '' ,
91+ 'onlyAllowStrongBox' : '$_onlyAllowStrongBox ' ,
8392 };
8493
8594 AndroidOptions copyWith ({
@@ -89,6 +98,7 @@ class AndroidOptions extends Options {
8998 StorageCipherAlgorithm ? storageCipherAlgorithm,
9099 String ? preferencesKeyPrefix,
91100 String ? sharedPreferencesName,
101+ bool ? onlyAllowStrongBox,
92102 }) =>
93103 AndroidOptions (
94104 encryptedSharedPreferences:
@@ -99,5 +109,6 @@ class AndroidOptions extends Options {
99109 storageCipherAlgorithm ?? _storageCipherAlgorithm,
100110 sharedPreferencesName: sharedPreferencesName,
101111 preferencesKeyPrefix: preferencesKeyPrefix,
112+ onlyAllowStrongBox: onlyAllowStrongBox ?? _onlyAllowStrongBox,
102113 );
103114}
0 commit comments