示例 Dart 加密许可证文件

这是关于如何在 Dart 中使用 Ed25519 签名验证和 AES-256-GCM 加密来验证和解密 加密许可证文件 的示例。

此示例验证了 aes-256-gcm+ed25519 算法。

运行示例

使用 dart pub 安装依赖项

dart pub get

然后运行示例程序,其中 -f 是许可证文件的路径,-k 是您的 Ed25519 公钥,-l 是许可证密钥。请随意使用这些示例值

dart run main.dart --license-file examples/license.lic \
  --license-key "9FB017-8E74A0-AC60C5-2C8BF6-2D2B90-V3" \
  --public-key "e8601e48b69383ba520245fd07971e983d06d22c4257cfd82304601479cee788"

您应该会看到输出,表明许可证文件有效,并显示其解密的数据集

license file was successfully verified!
  > {
      enc: F7g/36/UVMXnPCO7YGA6LaInutjxF06sU...fJCfqFqd5FiLYF33bR1qnYd2M9dfzM+XQ==.Jsw6jutQje0ZWmTn.n++MX8kfMTsqTZQjb2EFVg==,
      sig: VIOP81jRI4EHR7SY69k1O9AV79DNdYgU6uuiY6pR5o9z9Kgh6xli2eHYLVJCprhj2DIPnORD1xxsG22TqeXFDQ==,
      alg: aes-256-gcm+ed25519
    }
license file was successfully decrypted!
  > {
      data: {
        id: e2da9594-218f-41b6-a4d8-43c92b71a6c4,
        type: licenses,
        attributes: {name: Dart Example, ...},
        relationships: {...},
        links: {...}
      }
      included: [
        {id: a963360d-fafb-406a-bfe6-950bafc8bc00, type: products, ...},
        {id: f28621f6-34ec-42e7-84b5-2c659870399b, type: policies, ...},
        {id: 893201f7-e0f8-4a5a-99b5-c567e73f1366, type: users, ...},
        {id: c9e7a95c-e2ac-4580-b3d0-954b48b5c984, type: entitlements, ...},
        {id: dfb1cfce-8614-4ac7-82c4-f5eaa334ba96, type: entitlements, ...},
        {id: ecc6211a-f806-442f-b08a-aa2432d5837a, type: entitlements, ...}
      ],
      meta: {
        issued: 2022-10-04T21:34:54.589Z,
        expiry: 2023-10-04T21:34:54.589Z,
        ttl: 31556952
      }
    }

如果验证失败,请检查您的公钥。

如果解密失败,请检查您的许可证密钥。

有问题吗?

如果您有任何疑问或疑虑,请通过 [email protected] 与我们联系!

GitHub

查看 Github