kms 0.2.0 kms: ^0.2.0 copied to clipboard
Key Management Service (KMS) API for managing cryptographic keys securely.
Overview #
This package gives you a vendor-agnostic API for accessing Key Management Service (KMS) products. Many operating systems and major cloud platforms (AWS, Azure, Google) offer such APIs. KMS adapters are subclasses of Kms.
You may want to start with MemoryKms, which works in all platforms. It uses cryptographic implementations in our sibling project, package:cryptography.
Links #
Getting started #
1.Add dependency #
In pubspec.yaml:
dependencies:
kms: ^0.2.0
2.Use #
For key exchange #
import 'package:kms/kms.dart';
Future<void> main() async {
final kms = MemoryKms();
// Create our key pairs
final kmsKey = await kms.createKeyPair(
keyRingId: 'example',
keyExchangeType: KeyExchangeType.ecdhCurve25519, // Enable ECDH-Curve25519
signatureType: null, // Disable digital signature
);
// Generate a Curve25519 public key for the peer.
// In real life, you receive the public key from some source.
final peerKmsKey = await kms.createKeyPair(
keyRingId: 'example',
keyExchangeType: KeyExchangeType.ecdhCurve25519,
signatureType: null,
);
final peerPublicKey = await kms.getPublicKey(kmsKey1);
// Generate a shared secret key
final secretKey = await kms.sharedSecret(kmsKey, peerPublicKey);
print('Secret key: ${secretKey.bytes}');
// Delete the key pair
await kms.delete(kmsKey);
}
For digital signature #
import 'package:kms/kms.dart';
Future<void> main() async {
final kms = MemoryKms();
// Create the key pair
final kmsKey = await kms.createKeyPair(
keyRingId: 'example',
keyExchangeType: null, // Disable key exchange
signatureType: SignatureType.ecdsaP256Sha256, // Enable ECDSA-P256-SHA256
);
// Generate a signature
final data = <int>[1,2,3];
final signature = await kms.sign(data, kmsKey);
print('Signature: ${signature.bytes}');
print('Public key: ${signature.publicKey}');
// Delete the key pair
await kms.delete(kmsKey);
}