Import std.crypto.pem
Key
struct
Public Struct Key
A private or public key, as its kind's Methods take it: an ECDSA P-256 private key's 32 bytes or public key's 65; an RSA key's PKCS #1 DER, whose public one Rsa verifies with; and an X25519 or Ed25519 key's 32 bytes.
Examples
Local key = Key(KeyKind.ED25519, True, Ed25519.NewPrivateKey())
Local pem = key.ToPem()
Expect(pem.StartsWith("-----BEGIN PRIVATE KEY-----"))
Local read = Try Key.FromPem(pem)
Expect(read.Kind == KeyKind.ED25519 && read.IsPrivate && read.Bytes == key.Bytes)-
What kind of key it is.
-
Whether it's a private key, or a public one.
-
Its bytes, as its kind's Methods take them.
-
A key of
kind, private or public, ofbytes. -
The first key in
pem, whatever comes after it: a private one in PKCS #8 ("PRIVATE KEY"), SEC 1 ("EC PRIVATE KEY"), or PKCS #1 ("RSA PRIVATE KEY"), or a public one ("PUBLIC KEY", or "RSA PUBLIC KEY"). Throws a ParseError of SYNTAX whenpemhas no key, or one that doesn't read, and of WRONG_TYPE when it's encrypted, or of a kind there's no KeyKind for, like another curve's. -
The key as PEM, as OpenSSL writes it: a private one in PKCS #8, but an RSA one in PKCS #1 and a P-256 one in SEC 1, and a public one, RSA's too, in SubjectPublicKeyInfo. Panics when Bytes isn't a key of its Kind.
Report an issue with this page or with FutureBlitz on GitHub.