搜索插件、代码仓与 APP 分类

插件详情v1.0.0

crypto_keys_plus

一个用于执行加密签名/验证以及加密/解密的库。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
8万
喜欢数
3
Pub 分数
150

安装插件

flutter pub add crypto_keys_plus

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个专为加密操作(如签名、验证、加密和解密数据)设计的 Flutter/Dart 包。它提供了一种安全且跨平台的解决方案,可在 Android、iOS、Web、macOS、Windows 和 Linux 上处理敏感信息。该库以简单性为核心,使开发者无需深入掌握密码学知识即可实现强大的安全功能。该库在可用时利用底层原生加密 API,确保性能并符合各平台特定的安全标准。

适合场景

  • 安全数据传输
  • 数字签名验证
  • 端到端加密
  • 身份验证令牌保护
  • 敏感数据的安全本地存储
  • 遵守数据隐私法规

主要特点

  • 跨平台加密支持
  • 用于签名和加密的简单 API
  • 与原生加密库集成
  • 对多个平台的支持
  • 安全密钥管理
  • 开源且持续维护

适合对象

  • 开发安全应用的开发者
  • 需要数据完整性的应用
  • 处理用户身份验证的应用程序
  • 需要加密通信的项目
  • 优先考虑合规性和安全性

使用建议

  • 需要了解基本的密码学概念
  • 依赖于平台特定的加密实现
  • 不适合高性能加密工作负载
  • 必须遵循密钥管理最佳实践
  • 除了基本用法外,文档有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Build Status :heart: sponsor

A library for doing cryptographic signing/verifying and encrypting/decrypting.

It uses pointycastle under the hood, but exposes a more convenient api.

Usage

Signing

A simple usage example:

import 'package:crypto_keys/crypto_keys.dart';
import 'dart:typed_data';

main() {
  // Create a key pair from a JWK representation
  var keyPair = new KeyPair.fromJwk({
    "kty": "oct",
    "k": "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75"
        "aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow"
  });

  // A key pair has a private and public key, possibly one of them is null, if
  // required info was not available when construction
  // The private key can be used for signing
  var privateKey = keyPair.privateKey;

  // Create a signer for the key using the HMAC/SHA-256 algorithm
  var signer = privateKey.createSigner(algorithms.signing.hmac.sha256);

  // Sign some content, to be integrity protected
  var content = "It's me, really me";
  var signature = signer.sign("It's me, really me".codeUnits);

  print("Signing '$content'");
  print("Signature: ${signature.data}");

  // The public key can be used for verifying the signature
  var publicKey = keyPair.publicKey;

  // Create a verifier for the key using the specified algorithm
  var verifier = publicKey.createVerifier(algorithms.signing.hmac.sha256);

  var verified =
      verifier.verify(new Uint8List.fromList(content.codeUnits), signature);
  if (verified)
    print("Verification succeeded");
  else
    print("Verification failed");
}
Encryption

A simple usage example:


import 'package:crypto_keys/crypto_keys.dart';
import 'dart:typed_data';

main() {
  // Generate a new random symmetric key pair
  var keyPair = new KeyPair.generateSymmetric(128);

  // Use the public key to create an encrypter with the AES/GCM algorithm
  var encrypter =
      keyPair.publicKey.createEncrypter(algorithms.encryption.aes.gcm);

  // Encrypt the content with an additional authentication data for integrity
  // protection
  var content = "A very secret text";
  var aad = "It is me";
  var v = encrypter.encrypt(new Uint8List.fromList(content.codeUnits),
      additionalAuthenticatedData: new Uint8List.fromList(aad.codeUnits));

  print("Encrypting '$content'");
  print("Ciphertext: ${v.data}");
  print("Authentication tag: ${v.authenticationTag}");

  // Use the private key to create the decrypter
  var decrypter =
      keyPair.privateKey.createEncrypter(algorithms.encryption.aes.gcm);

  // Decrypt and verify authentication tag
  var decrypted = decrypter.decrypt(v);

  print("Decrypted text: '${new String.fromCharCodes(decrypted)}'");
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Sponsor

Creating and maintaining this package takes a lot of time. If you like the result, please consider to :heart: sponsor. With your support, I will be able to further improve and support this project.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目