mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-10-18 23:07:27 +02:00
[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:
1 parent
b3e52ce036
commit
0374bec1e2
19 files changed
+915
-141
No files matched your search
@@ -8,6 +8,8 @@
|
||||
"nfc:allow-write",
|
||||
"nfc:allow-scan",
|
||||
"biometric:allow-authenticate",
|
||||
"biometric:allow-status",
|
||||
"biometric:allow-biometric-cipher",
|
||||
"barcode-scanner:allow-scan",
|
||||
"barcode-scanner:allow-cancel",
|
||||
"barcode-scanner:allow-request-permissions",
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
<script>
|
||||
import { authenticate } from "@tauri-apps/plugin-biometric";
|
||||
import { authenticate, biometricCipher } from "@tauri-apps/plugin-biometric";
|
||||
import * as os from "@tauri-apps/plugin-os";
|
||||
|
||||
export let onMessage;
|
||||
let allowDeviceCredential = true;
|
||||
|
||||
const isAndroid = os.platform() === "android";
|
||||
let plainText = "";
|
||||
let encryptedData = "";
|
||||
|
||||
function auth() {
|
||||
authenticate("Tauri API wants to show it is awesome :)", {
|
||||
allowDeviceCredential,
|
||||
@@ -17,14 +22,62 @@
|
||||
.then(onMessage)
|
||||
.catch(onMessage);
|
||||
}
|
||||
|
||||
function encrypt() {
|
||||
biometricCipher("Authenticate to encrypt the data", {
|
||||
title: "Tauri API Encrypt",
|
||||
cancelTitle: "Cancel",
|
||||
dataToEncrypt: plainText,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
encryptedData = data;
|
||||
onMessage(`Encrypted: ${data}`);
|
||||
})
|
||||
.catch(onMessage);
|
||||
}
|
||||
|
||||
function decrypt() {
|
||||
biometricCipher("Authenticate to decrypt the data", {
|
||||
title: "Tauri API Decrypt",
|
||||
cancelTitle: "Cancel",
|
||||
dataToDecrypt: encryptedData,
|
||||
})
|
||||
.then(({ data }) => onMessage(`Decrypted: ${data}`))
|
||||
.catch(onMessage);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="dllowDeviceCredential"
|
||||
id="allowDeviceCredential"
|
||||
bind:checked={allowDeviceCredential}
|
||||
/>
|
||||
<label for="allowDeviceCredentiale">Allow device credential</label>
|
||||
<label for="allowDeviceCredential">Allow device credential</label>
|
||||
</div>
|
||||
<button class="btn" id="cli-matches" on:click={auth}> Authenticate </button>
|
||||
<button class="btn" id="biometric-authenticate" on:click={auth}>
|
||||
Authenticate
|
||||
</button>
|
||||
|
||||
{#if isAndroid}
|
||||
<div class="flex flex-col gap-2 mt-4">
|
||||
<h3>Biometric cipher</h3>
|
||||
<input class="input" placeholder="Data to encrypt" bind:value={plainText} />
|
||||
<button class="btn" id="biometric-encrypt" on:click={encrypt}>
|
||||
Encrypt
|
||||
</button>
|
||||
<input
|
||||
class="input"
|
||||
placeholder="Encrypted data"
|
||||
bind:value={encryptedData}
|
||||
/>
|
||||
<button
|
||||
class="btn"
|
||||
id="biometric-decrypt"
|
||||
disabled={!encryptedData}
|
||||
on:click={decrypt}
|
||||
>
|
||||
Decrypt
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
Reference in new issue
Block a user