Flutter OTP迁移辅助插件otpauth_migration的使用
Flutter OTP迁移辅助插件otpauth_migration的使用
简介
otpauth_migration
是一个 Dart 包,用于编码和解码 otpauth-migration
URI 格式。这种格式用于从 Google Authenticator 应用程序导入和导出双因素认证 (2FA) 密钥。
特性
- OtpAuthMigration - 主类(无状态)
- String OtpAuthMigration.encode(List<String> uris) - 将多个 OTP URI 编码为迁移 URI。
- List<String> OtpAuthMigration.decode(String uri) - 将迁移 URI 解码为多个 OTP URI。
要求
- Dart 2.16.1
导入
import 'package:otpauth_migration/otpauth_migration.dart';
使用
示例1:解码迁移URI
final otpAuthParser = OtpAuthMigration();
var otp_uris = otpAuthParser.decode("otpauth-migration://offline?data=Cj8KFGnEpnTMQ7KDguNWnddyGyCbSVLaEhhBQ01FIENvOmpvaG5AZXhhbXBsZS5jb20aB0FDTUUgQ28gASgBMAIKRAoUXkj+5MY2arwKjsnH2aDsbm6TAlYSG0JldGEgTHRkLjpob21lckBleGFtcGxlLmNvbRoJQmV0YSBMdGQuIAEoATACCkgKFDDFyzUNPgYoI3q/KGHBdcNU9ptWEh1DYXRzICYgRG9nczptYXJnZUBleGFtcGxlLmNvbRoLQ2F0cyAmIERvZ3MgASgBMAIKSAoUunHzbm5h/LUO0yilLMI+dYZY1eISHURhaWx5IEJ1Z2xlOnBldGVyQGV4YW1wbGUuY29tGgtEYWlseSBCdWdsZSABKAEwAhABGAEgACjDnb+uAg==");
// otp_uris = [
// "otpauth://totp/ACME Co:john.doe@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME Co",
// "otpauth://totp/Beta Ltd:john@exaple.com?secret=JBSWY3DPEHPK3PXP&issuer=Beta Ltd"
// ]
print(otp_uris);
示例2:编码为迁移URI
final otpAuthParser = OtpAuthMigration();
var otp_migration = otpAuthParser.encode([
"otpauth://totp/ACME%20Co:john.doe@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME+Co",
"otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
]);
// otp_migration =
// "otpauth-migration://offline?data=CkMKFD3GyqSCSm0oh2eyMx4gtDFmy4XZEhxBQ01FIENvOmpvaG4uZG9lQGV4YW1wbGUuY29tGgdBQ01FIENvIAEoATACCjUKCkhlbGxvId6tvu8SGEV4YW1wbGU6YWxpY2VAZ29vZ2xlLmNvbRoHRXhhbXBsZSABKAEwAhABGAEgACjn4Pv4Ag=="
print(otp_migration);
测试
% dart test
示例代码
可以在 example
文件夹中找到更多的示例代码。
% cd example
% dart run otpauth_migration_example.dart
额外信息
- 需要对输入进行更多的错误检查(并添加相关的测试)
- 修复版本、batchSize、batchIndex、batchId
- 添加 Github Actions 徽章(以显示 Github Action 测试结果)
- RFC 3548 描述(以及图示)
构建
% protoc -I=./proto --dart_out=lib/generated proto/GoogleAuthenticatorImport.proto
API 文档
% dart doc .
格式化和分析
% dart analyze
% dart format .
发布
% dart pub publish
更多关于Flutter OTP迁移辅助插件otpauth_migration的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复