[feat] [biometric] Adding the capability of encrypting/decrypting data using biometric authentication on Android (Ref. #2306) (#2454)

* –feat: adding the ability to encrypt/decrypt data based on the biometric auth

Adding the method biometricCipher() that allows to use the biometric authentication to use a generated key from android that can be accessed only through the biometric authentication. The method uses this key to encrypt/decrypt the data provided by the caller in the "options" parameter, with "dataToEncrypt" or "dataToDecrypt" filled.

Changes were done both on Kotlin, Rust and JS sides.

* Improving the way we encrypt data by allowing only if the biometric was successful.

* Adding a warning on the JS side

* Adding doc changes in readme.md

* Adding doc changes in readme.md

* Update README.md - it was updated incomplete

* update docs

* enhance error handling

* update example

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Charles SchaeferandLucas Nogueira authored and GitHub committed 2026-10-12 10:38:16 -03:00
1 parent b3e52ce036
commit 0374bec1e2
19 files changed
+915 -141

No files matched your search

+1
View File
@@ -33,6 +33,7 @@ pub(crate) async fn authenticate<R: Runtime>(
title,
subtitle,
confirmation_required,
..Default::default()
};
// The prompt blocks until the user answers, so keep it off the async runtime workers.
tauri::async_runtime::spawn_blocking(move || app.biometric().authenticate(reason, options))
+13
View File
@@ -53,4 +53,17 @@ impl<R: Runtime> Biometric<R> {
.run_mobile_plugin("authenticate", AuthenticatePayload { reason, options })
.map_err(Into::into)
}
/// Prompts the user for biometric authentication and, on success, encrypts
/// [`AuthOptions::data_to_encrypt`] or decrypts [`AuthOptions::data_to_decrypt`] using a key
/// protected by the device's strong biometrics. **Android only.**
pub fn biometric_cipher(
&self,
reason: String,
options: AuthOptions,
) -> crate::Result<CipherResult> {
self.0
.run_mobile_plugin("biometricCipher", AuthenticatePayload { reason, options })
.map_err(Into::into)
}
}
+11
View File
@@ -12,6 +12,10 @@ pub struct AuthOptions {
pub allow_device_credential: bool,
/// Label for the Cancel button. This feature is available on Android, iOS and macOS.
pub cancel_title: Option<String>,
/// The plain data that must be encrypted after successful biometric authentication. **Android only.**
pub data_to_encrypt: Option<String>,
/// The encrypted data that must be decrypted after successful biometric authentication. **Android only.**
pub data_to_decrypt: Option<String>,
/// Specifies the text displayed on the fallback button if biometric authentication fails. This feature is available on iOS and macOS only.
pub fallback_title: Option<String>,
/// Title indicating the purpose of biometric verification. This feature is available Android only.
@@ -50,3 +54,10 @@ pub struct Status {
/// Only set when [`Self::is_available`] is `false`.
pub error_code: Option<String>,
}
/// The result of [`Biometric::biometric_cipher`](crate::Biometric::biometric_cipher).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CipherResult {
/// The encrypted or decrypted data.
pub data: String,
}