颤振,将3字符串转换为sha1

时间:2020-09-29 04:47:33

标签: flutter dart

我有这个方块:

String date = DateTime.now() as String;
String phone1 = phone;
String secretKey = secret_key;

var date_ = utf8.encode(date);
var phone_ = utf8.encode(phone1);

它可以同时使用多个参数和加号吗?

  var signature = sha1.convert(date_ + phone_ + secretKey);

2 个答案:

答案 0 :(得分:0)

好吧,最好在调用conda install cvxpot之前先做plus

因此,请尝试以下操作:

utf8.encode

答案 1 :(得分:0)

您可以在下面复制粘贴运行完整代码
要从多个块生成摘要,可以使用startChunkedConversion
您可以reference了解详情
代码段

String date = DateTime.now().toString();
String phone1 = 'phone';
String secretKey = 'secret_key';

List<List<int>> bytesChunks = [
  utf8.encode(date),
  utf8.encode(phone1),
  utf8.encode(secretKey),
];

var output = new AccumulatorSink<Digest>();

ByteConversionSink input = sha1.startChunkedConversion(output);
bytesChunks.forEach((List<int> bytes) {
  input.add(bytes);
});
input.close();

Digest result = output.events.single;

print('Result: $result');

完整代码

import 'package:flutter/material.dart';
import 'package:crypto/crypto.dart';
import 'package:convert/convert.dart';
import 'dart:convert';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    String date = DateTime.now().toString();
    String phone1 = 'phone';
    String secretKey = 'secret_key';

    List<List<int>> bytesChunks = [
      utf8.encode(date),
      utf8.encode(phone1),
      utf8.encode(secretKey),
    ];

    var output = new AccumulatorSink<Digest>();

    ByteConversionSink input = sha1.startChunkedConversion(output);
    bytesChunks.forEach((List<int> bytes) {
      input.add(bytes);
    });
    input.close();

    Digest result = output.events.single;

    print('Result: $result');

    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}