暗号化
純粋なDartで実装された暗号関数のセット。
- スター
- 268
- フォーク
- 50
- 最終プッシュ(UTC)
- 2024/10/17
- プロジェクト状態
- アーカイブ済み
元の README
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
[!IMPORTANT]
This repo has moved to https://github.com/dart-lang/core/tree/main/pkgs/crypto
A set of cryptographic hashing functions for Dart.
The following hashing algorithms are supported:
- SHA-1
- SHA-224
- SHA-256
- SHA-384
- SHA-512
- SHA-512/224
- SHA-512/256
- MD5
- HMAC (i.e. HMAC-MD5, HMAC-SHA1, HMAC-SHA256)
Usage
Digest on a single input
To hash a list of bytes, invoke the convert method on the
sha1, sha256 or md5
objects.
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 = sha1.convert(bytes);
print("Digest as bytes: ${digest.bytes}");
print("Digest as hex string: $digest");
}
Digest on chunked input
If the input data is not available as a single list of bytes, use the chunked conversion approach.
Invoke the startChunkedConversion method
to create a sink for the input data. On the sink, invoke the add
method for each chunk of input data, and invoke the close method
when all the chunks have been added. The digest can then be retrieved
from the Sink<Digest> used to create the input data sink.
import 'dart:convert';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
void main() {
var firstChunk = utf8.encode("foo");
var secondChunk = utf8.encode("bar");
var output = AccumulatorSink<Digest>();
var input = sha1.startChunkedConversion(output);
input.add(firstChunk);
input.add(secondChunk); // call `add` for every chunk of input data
input.close();
var digest = output.events.single;
print("Digest as bytes: ${digest.bytes}");
print("Digest as hex string: $digest");
}
The above example uses the AccumulatorSink class that comes with the
convert package. It is capable of accumulating multiple events, but
in this usage only a single Digest is added to it when the data sink's
close method is invoked.
HMAC
Create an instance of the Hmac class with the hash function
and secret key being used. The object can then be used like the other
hash calculating objects.
import 'dart:convert';
import 'package:crypto/crypto.dart';
void main() {
var key = utf8.encode('p@ssw0rd');
var bytes = utf8.encode("foobar");
var hmacSha256 = Hmac(sha256, key); // HMAC-SHA256
var digest = hmacSha256.convert(bytes);
print("HMAC digest as bytes: ${digest.bytes}");
print("HMAC digest as hex string: $digest");
}
Disclaimer
Support for this library is given as best effort.
This library has not been reviewed or vetted by security professionals.
使用している依存関係
依存関係一覧 4 件
- typed_data
^1.3.0 - convert開発用
^3.0.0 - dart_flutter_team_lints開発用
^3.0.0 - test開発用
^1.16.6
プロジェクトに合うリポジトリを選ぶには?
用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。
- 名前・作者・説明で検索し、技術トピックで絞り込みます。
- スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
- 利用前に GitHub で README、ライセンス、Issues を確認します。
情報源と管理
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗