FirebaseAESLib.Mobile
1.0.7
dotnet add package FirebaseAESLib.Mobile --version 1.0.7
NuGet\Install-Package FirebaseAESLib.Mobile -Version 1.0.7
<PackageReference Include="FirebaseAESLib.Mobile" Version="1.0.7" />
<PackageVersion Include="FirebaseAESLib.Mobile" Version="1.0.7" />
<PackageReference Include="FirebaseAESLib.Mobile" />
paket add FirebaseAESLib.Mobile --version 1.0.7
#r "nuget: FirebaseAESLib.Mobile, 1.0.7"
#:package FirebaseAESLib.Mobile@1.0.7
#addin nuget:?package=FirebaseAESLib.Mobile&version=1.0.7
#tool nuget:?package=FirebaseAESLib.Mobile&version=1.0.7
Got it ๐ โ you want the Markdown sample guide written exactly inside a single file, no extra explanations from me. Here it is, clean:
# FirebaseAESLib.Mobile Xamarin.Forms Sample
This is a minimal sample Xamarin.Forms app using the `FirebaseAESLib.Mobile` NuGet package to securely encrypt and decrypt Firebase Realtime Database data with AES encryption.
## ๐ง Requirements
- Xamarin.Forms (>= 5.0.0)
- .NET Standard 2.0 compatible platform (Android/iOS)
- Firebase project with Realtime Database enabled
## ๐ฆ Install Packages
Add this package to your Xamarin shared project
nuget install FirebaseAESLib.Mobile -Version 1.0.3
Or using .NET CLI:
dotnet add package FirebaseAESLib.Mobile --version 1.0.3
dotnet add package DotNetEnv
## ๐ Folder Structure
MyFirebaseAESApp/ โโโ Models/ โ โโโ Member.cs โ โโโ RawMember.cs โโโ Views/ โ โโโ MainPage.xaml โโโ MainPage.xaml.cs โโโ .env โโโ App.xaml.cs โโโ App.xaml
## ๐งช Sample `.env` File
Place this in the root of your shared project:
AES_KEY=your-base64-encoded-256bit-key AES_IV=your-base64-encoded-128bit-iv FIREBASE_PROJECT_ID=your-project-id FIREBASE_ID_TOKEN=your-firebase-user-id-token
## ๐งฌ How It Works
- ๐ Encrypts each field using AES before pushing to Firebase
- ๐ Decrypts data after reading it back
- ๐ Uses `.env` for storing Firebase project credentials and AES keys
## ๐งพ Code Overview
### 1. Define your encrypted `Member` model
`Models/Member.cs`
```csharp
public class Member
{
public string Name { get; set; }
public string Age { get; set; }
public string Gender { get; set; }
public string Phone { get; set; }
public string Residence { get; set; }
public string RegistrationDateTime { get; set; }
public DateTime LogDetailDateTime { get; set; }
public int AgeInt => int.TryParse(Age, out var r) ? r : 0;
}
2. Define a raw display model for encrypted content
Models/RawMember.cs
public class RawMember
{
public string Key { get; set; }
public Dictionary<string, object> Fields { get; set; }
public string Name => Get("Name");
public string Age => Get("Age");
private string Get(string key) =>
Fields != null && Fields.TryGetValue(key, out var v) ? v?.ToString() ?? "" : "";
}
3. MainPage UI Layout
Views/MainPage.xaml
<ContentPage ...>
<StackLayout Padding="10">
<Entry x:Name="NameEntry" Placeholder="Enter Name" />
<Entry x:Name="AgeEntry" Placeholder="Enter Age" Keyboard="Numeric" />
<Button Text="Save Member" Clicked="OnSaveClicked" />
<Button Text="Load Members" Clicked="OnLoadClicked" />
<ListView x:Name="MainListView" />
</StackLayout>
</ContentPage>
4. Logic: Save & Load Encrypted Data
MainPage.xaml.cs
public partial class MainPage : ContentPage
{
private RealtimeRestClient _firebase;
private AesEncryptor _aes;
public MainPage()
{
InitializeComponent();
Env.Load(); // ๐ Load .env variables
var key = Environment.GetEnvironmentVariable("AES_KEY");
var iv = Environment.GetEnvironmentVariable("AES_IV");
var pid = Environment.GetEnvironmentVariable("FIREBASE_PROJECT_ID");
var token = Environment.GetEnvironmentVariable("FIREBASE_ID_TOKEN");
_aes = new AesEncryptor(key, iv);
_firebase = new RealtimeRestClient(pid, token, _aes);
}
// ๐ Encrypt and push data
private async void OnSaveClicked(object sender, EventArgs e)
{
var member = new Dictionary<string, object>
{
{ "Name", NameEntry.Text },
{ "Age", AgeEntry.Text },
{ "Gender", "MALE" },
{ "Phone", "+123456789" },
{ "Residence", "NAIROBI" },
{ "RegistrationDateTime", DateTime.Now.ToString("dd MMM yyyy") },
{ "LogDetailDateTime", DateTime.UtcNow.ToString("o") }
};
await _firebase.PushEncryptedAsync("DemoApp/Members", member);
await DisplayAlert("Saved", "Member saved to Firebase.", "OK");
}
// ๐ Read and decrypt data
private async void OnLoadClicked(object sender, EventArgs e)
{
var url = _firebase.BuildUrl("DemoApp/Members");
var json = await new HttpClient().GetStringAsync(url);
var raw = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, object>>>(json);
var members = new List<Member>();
foreach (var item in raw)
{
var decrypted = _aes.DecryptDictionary(item.Value);
var memJson = JsonSerializer.Serialize(decrypted);
var member = JsonSerializer.Deserialize<Member>(memJson);
members.Add(member);
}
MainListView.ItemsSource = members;
}
}
5. App Startup
App.xaml.cs
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
protected override void OnStart() => DotNetEnv.Env.Load();
}
โ Result
- AES encrypted member data is stored securely in Firebase.
- On retrieval, data is decrypted and shown in your mobile app.
๐ Learn More
๐ GitHub: FirebaseAESLibMobile)
MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Security.Cryptography.Algorithms (>= 4.3.1)
- System.Text.Json (>= 9.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.