pem 2.0.5 copy "pem: ^2.0.5" to clipboard
pem: ^2.0.5 copied to clipboard

PEM encoding/decoding of textual keys following RFC 7468, supporting both lax/strict-mode, and certificates chains of concatenated PEM blocks.

PEM Encoding/Decoding for Dart #

Encoding/decoding of PEM (Privacy-Enhanced Mail) textual key encoding following RFC 7468.

Disclaimer: This is not an officially supported Google product.

To maximize interoperabilty encoding methods in this package always produces strict-mode output. While decoding methods defaults to lax-mode which ignores extra whitespace, line breaks, tabs as specified in RFC 7468.

Decoding methods ignore text surrounding the PEM blocks, this also implies that decoding methods cannot distinguish between malformed PEM blocks and text to be ignored. Thus, malformed PEM blocks will not cause exceptions to be thrown, though the PemCodec will throw if no PEM block with acceptable label is present.

Example #

import 'package:pem/pem.dart';

// Parse PEM encoded private key.
List<int> keyData = PemCodec(PemLabel.privateKey).decode("""
  -----BEGIN PRIVATE KEY-----
  MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgVcB/UNPxalR9zDYAjQIf
  jojUDiQuGnSJrFEEzZPT/92hRANCAASc7UJtgnF/abqWM60T3XNJEzBv5ez9TdwK
  H0M6xpM2q+53wmsN/eYLdgtjgBd3DBmHtPilCkiFICXyaA8z9LkJ
  -----END PRIVATE KEY-----
""");

// Encode keyData as PEM string.
String pemBlock = PemCodec(PemLabel.privateKey).encode(keyData);

// Print encoded block (should print what we parsed, without indentation)
print(pemBlock);

See API reference for further details and examples on how to parse documents containing multiple PEM blocks, as is often the case for certificate chains.

18
likes
140
pub points
92%
popularity

Publisher

verified publishergoogle.dev

PEM encoding/decoding of textual keys following RFC 7468, supporting both lax/strict-mode, and certificates chains of concatenated PEM blocks.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#crypto #security #parser #pem

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

petitparser

More

Packages that depend on pem