Flutter:MD5加密解密哈希函數

最近更新時間 2019-12-28 20:22:58

純Dart實現的一組加密哈希函數,支持以下哈希算法:

  • SHA-1
  • SHA-224
  • SHA-256
  • SHA-384
  • SHA-512
  • MD5
  • HMAC (i.e. HMAC-MD5, HMAC-SHA1, HMAC-SHA256)

安裝

1. 在配置文件 pubspec.yaml中添加依賴,如下所示:

dependencies:
  crypto: ^2.1.4

2. 命令行安裝軟件包:

pub get

flutter pub get

3. Import it

import 'package:crypto/crypto.dart';

使用

字符串MD5加密

import 'package:crypto/crypto.dart';
import 'dart:convert'; // for the utf8.encode method

void main() {
  var bytes = utf8.encode("foobar"); // data being hashed

  var digest = md5.convert(bytes);

  print("Digest as bytes: ${digest.bytes}");
  print("Digest as hex string: $digest");
}

 

rss_feed