android - 在颤动中将指纹读取为字符串
问题描述
我有一个在 android 上运行的应用程序,它使用指纹进行身份验证。该应用程序正在运行,它正在返回我想要的。但我仍然想读取指纹散列或字符串,以便我可以为另一个项目散列它。到目前为止我的代码:
main.dart
import 'package:fingerprint/secondpage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: FingerprintApp(),
));
}
class FingerprintApp extends StatefulWidget{
@override
_FingerprintAppState createState() => _FingerprintAppState();
}
class _FingerprintAppState extends State<FingerprintApp>{
LocalAuthentication auth = LocalAuthentication();
bool _canCheckBiometric ;
List<BiometricType> _availableBiometrics;
String autherized = "Not autherized";
Future<void> _checkBiometric() async {
bool canCheckBiometric;
try {
canCheckBiometric = await auth.canCheckBiometrics;
} on PlatformException catch (e) {
print(e);
}
if (!mounted) return;
setState(() {
_canCheckBiometric = canCheckBiometric;
});
}
Future<void> _getAvailableBiometric() async {
List<BiometricType> availableBiometric;
try{
availableBiometric = await auth.getAvailableBiometrics();
} on PlatformException catch (e){
print(e);
}
setState(() {
_availableBiometrics = availableBiometric;
});
}
Future<void> _authenticate() async{
bool authenticated = false;
try{
authenticated = await auth.authenticateWithBiometrics(
localizedReason: "Scan your finger to authenticate",
useErrorDialogs: true,
stickyAuth: false
);
} on PlatformException catch(e){
print(e);
}
if (!mounted) return;
setState(() {
autherized = authenticated ? "Autherized success":"Failed to authenticate";
if(authenticated){
Navigator.push(context,MaterialPageRoute(builder: (context) => SecondPage()));
}
print(autherized);
});
}
@override
void initState(){
_checkBiometric();
_getAvailableBiometric();
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Color(0xFF07496D),
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text("Login",style: TextStyle(
color: Colors.white,
fontSize: 48.0,
fontWeight: FontWeight.bold
),),
),
Container(
margin: EdgeInsets.symmetric(vertical: 50.0),
child: Column(
children: <Widget>[
Image.asset(
'assets/fingerprint.png',
width: 120.0,
),
Text("Fingerprint Auth", style: TextStyle(
color: Colors.white,
fontSize: 22.0,
fontWeight: FontWeight.bold,
),),
Container(
width: 150.0,
margin: EdgeInsets.symmetric(vertical: 15.0),
child: Text("Authenticate with your fingerprint instead of your password",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
height: 1.5,
),
),
),
Container(
margin: EdgeInsets.symmetric(vertical: 15.0 ),
width: double.infinity,
child: RaisedButton(
onPressed: _authenticate,
elevation: 0.0,
color: Color(0xFF04A5ED),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
child: Padding(
padding: EdgeInsets.symmetric(vertical:14.0,horizontal: 24.0),
child: Text("Authenticate", style: TextStyle(
color: Colors.white,
),),
)
)
)
]
)
)
],
),
) ,
),
);
}
}
androidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fingerprint">
<uses-permission android:name="android.permission.USE_FINGERPRINT"></uses-permission>
<application
android:label="fingerprint"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
发布规范.yaml
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
local_auth: ^0.4.0+1
当我运行这个应用程序时,它需要一个指纹并接受我移动到另一个页面。但是有什么方法可以读取 sha256 或 sha1 中的指纹或字符串?我想将此指纹保存在文件中以备将来使用。
解决方案
推荐阅读
- excel - 如果单元格中的值等于下降,有没有办法删除活动行?
- c# - 将构建在 64 位系统上的 C# 应用程序匹配到在 32 位系统上运行
- sql - 需要帮助将 3 列的结果合并为 1 (SQL Server 2012)
- javascript - 为什么日期/时间在 node.js 控制台中输出“未定义”?
- svg - IDML 多边形到 SVG
- ios - 为什么 Flatlist 中的图像有时无法渲染?
- javascript - 为什么添加两个单元素数组给我一个字符串并减去它们给我一个数字?
- php - 标量和返回类型声明可以同时使用吗?
- python - setuptools 安装程序在 Jenkins 的 Docker 构建中失败
- ios - 我正在尝试 Segue 并传递一个字符串,但出现错误