FirebaseAESLib.Mobile
1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FirebaseAESLib.Mobile --version 1.0.3
NuGet\Install-Package FirebaseAESLib.Mobile -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FirebaseAESLib.Mobile" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FirebaseAESLib.Mobile" Version="1.0.3" />
<PackageReference Include="FirebaseAESLib.Mobile" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FirebaseAESLib.Mobile --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FirebaseAESLib.Mobile, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FirebaseAESLib.Mobile@1.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FirebaseAESLib.Mobile&version=1.0.3
#tool nuget:?package=FirebaseAESLib.Mobile&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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. Add this to the app.xaml.cs to load .env
public static void LoadEnvFromEmbedded()
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var resourceName = "your-solution..env";
foreach (var name in assembly.GetManifestResourceNames())
{
System.Diagnostics.Debug.WriteLine($"[Resource] {name}");
}
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
var envContent = reader.ReadToEnd();
foreach (var line in envContent.Split('\n'))
{
var match = Regex.Match(line.Trim(), @"^([A-Za-z0-9_]+)=(.*)$");
if (match.Success)
{
var key = match.Groups[1].Value;
var value = match.Groups[2].Value.Trim();
Environment.SetEnvironmentVariable(key, value);
System.Diagnostics.Debug.WriteLine($"[Env] Loaded: {key} = {value}");
}
}
}
var apiKey = Environment.GetEnvironmentVariable("FIREBASE_API_KEY");
System.Diagnostics.Debug.WriteLine($"[Env] FIREBASE_API_KEY: {apiKey}");
}
1. Define your encrypted Member
model
Models/Member.cs
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: FirebaseAESLib)
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.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.