shortdramadb / nativephp-secure-storage
NativePHP Mobile plugin: secure storage in the iOS Keychain and Android Keystore, behind NativePHP's SecureStorage facade
Package info
github.com/Matse2005/nativephp-secure-storage
Language:Kotlin
Type:nativephp-plugin
pkg:composer/shortdramadb/nativephp-secure-storage
Requires
- php: ^8.3
- nativephp/mobile: ^4.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The native side of NativePHP's own SecureStorage facade. NativePHP Mobile v4 ships the facade
(Native\Mobile\Facades\SecureStorage) but not the native code behind it. This plugin supplies the three bridge
functions the facade calls, so apps use the facade unchanged:
| Bridge function | Facade call |
|---|---|
SecureStorage.Set |
SecureStorage::set($key, $value, $accessibility); a null value deletes the key |
SecureStorage.Get |
SecureStorage::get($key) and SecureStorage::read($key) |
SecureStorage.Delete |
SecureStorage::delete($key) |
Storage
- iOS: generic password items in the Keychain, one service per app (
<bundle id>.secure-storage). Items use theThisDeviceOnlyaccessibility classes, so they never sync to iCloud or restore onto another device.SecureStorageAccessibility::WhenUnlocked(default),AfterFirstUnlockandWhenPasscodeSetmap to the matching classes. A read on a locked device answersunavailable, notnot_found. - Android: AES-256-GCM with a key kept in the Android Keystore (hardware-backed where the device supports it). Only the
ciphertext goes into a private SharedPreferences file. A value restored from a backup onto another device cannot be
decrypted there; it reads as
not_foundand is dropped. Platform APIs only, noandroidx.security.
Install
composer require shortdramadb/nativephp-secure-storage php artisan native:plugin:register shortdramadb/nativephp-secure-storage php artisan native:plugin:list
The native code is compiled into your own builds (native:run, native:package). The Jump preview app does not
contain it, so under Jump the facade reports a failure: keep a fallback for development.
Testing
Under a test runner the plugin adds macros to NativePHP's fake bridge:
Native::fakeBridge()->withSecureStorage(['api_token' => 'abc']); // in-memory keychain Native::fakeBridge()->assertStored('api_token'); Native::fakeBridge()->assertDeleted('api_token'); Native::fakeBridge()->assertNothingStored();