catalyst_cose 0.2.0 copy "catalyst_cose: ^0.2.0" to clipboard
catalyst_cose: ^0.2.0 copied to clipboard

A dart plugin implementing CBOR Object Signing and Encryption (RFC 9052, RFC 9053).

example/main.dart

// ignore_for_file: avoid_print

import 'dart:convert';

import 'package:catalyst_cose/catalyst_cose.dart';
import 'package:cbor/cbor.dart';
import 'package:convert/convert.dart';
import 'package:cryptography/cryptography.dart';

Future<void> main() async {
  final algorithm = Ed25519();
  final keyPair = await algorithm.newKeyPairFromSeed(List.filled(32, 0));
  final privateKey = await keyPair.extractPrivateKeyBytes();
  final publicKey = await keyPair.extractPublicKey().then((e) => e.bytes);

  final payload = utf8.encode('This is the content.');

  final coseSign1 = await CatalystCose.sign1(
    privateKey: privateKey,
    payload: payload,
    kid: CborBytes(publicKey),
  );

  final verified = await CatalystCose.verifyCoseSign1(
    coseSign1: coseSign1,
    publicKey: publicKey,
  );

  print('COSE_SIGN1:');
  print(hex.encode(cbor.encode(coseSign1)));
  print('verified: $verified');

  assert(
    verified,
    'The signature proves that given COSE_SIGN1 structure has been '
    'signed by the owner of the given public key',
  );
}
0
likes
0
points
257
downloads

Publisher

verified publisherprojectcatalyst.io

Weekly Downloads

A dart plugin implementing CBOR Object Signing and Encryption (RFC 9052, RFC 9053).

Repository (GitHub)
View/report issues

Topics

#cryptography #encryption #codec

License

unknown (license)

Dependencies

cbor, convert, cryptography

More

Packages that depend on catalyst_cose