std/crypto¶
module crypto
Keys, signatures, MACs, password hashes and encryption. An algorithm and
a key format are each named by a type, as a format is:
PublicKey(text, Pem, Ed25519). A key's type carries its algorithm, so a
key of one algorithm used where another is named is a check error.
PrivateKey, KeyPair and SecretKey are Secret: no format writes
one, == does not compare them, and each prints redacted.
KeyAlgorithm— An asymmetric key algorithm.Signing— An asymmetric key algorithm.Agreement— An asymmetric key algorithm.Ed25519— An asymmetric key algorithm.P256— An asymmetric key algorithm.Rsa— An asymmetric key algorithm.X25519— An asymmetric key algorithm.SecretAlgorithm— A symmetric algorithm: aCipherencrypts, aMacauthenticates.Cipher— A symmetric algorithm: aCipherencrypts, aMacauthenticates.Mac— A symmetric algorithm: aCipherencrypts, aMacauthenticates.Aes256Gcm— A symmetric algorithm: aCipherencrypts, aMacauthenticates.ChaCha20Poly1305— A symmetric algorithm: aCipherencrypts, aMacauthenticates.HmacSha256— A symmetric algorithm: aCipherencrypts, aMacauthenticates.HmacSha512— A symmetric algorithm: aCipherencrypts, aMacauthenticates.Secret— The values that hold private key material: no format encodes one,==does not compare them, and each prints redacted.PublicKey— A public key of algorithmA.PrivateKey— A private key of algorithmA.KeyPair— A private key and its public key.SecretKey— A symmetric key of algorithmA.KeyFormat— How one key is text.Pem— How one key is text.Jwk— How one key is text.OpenSsh— How one key is text.Age— How one key is text.to_public_key— The public keyselfholds informat, ornone.to_private_key— The private keyselfholds informat, ornone.read_public_key— The public key a file holds informat.read_private_key— The private key a file holds informat.to_text—selfwritten informat:key.to_text(OpenSsh)is anssh-ed25519 AAAA…line.to_der—selfas SPKI DER.export_private— The private key material ofselfwritten informat, encrypted underpassphrasewhere one is given: PKCS #8 with scrypt and AES-256-CBC forPem, bcrypt-pbkdf and AES-256-CTR forOpenSsh.public— The public key of a private key.thumbprint— The RFC 7638 JWK thumbprint ofself: base64url, unpadded, of the SHA-256 of its canonical JWK.generate_key_pair— A new key pair from the host's cryptographically secure generator.generate_secret_key— A new symmetric key from the host generator: 32 octets for a cipher andHmacSha256, 64 forHmacSha512.sign— The signature of the octets ofselfbykey.sign_data— The signature ofcanonical(self), the RFC 8785 text of the tree, so two trees equal under HQL equality have one signature.verify— Whethersignatureiskey's signature ofself:false, never an error, for a signature of another key, of the wrong length or malformed.verify_data— Whethersignatureiskey's signature ofcanonical(self).p256_signature_from_der— Ther || sform of an ASN.1 DER ECDSA P-256 signature, as OpenSSL writes one, ornonewhereselfis not one.mac— The HMAC tag ofselfunderkey: 32 octets forHmacSha256, 64 forHmacSha512.verify_mac— Whethertagis the MAC tag ofselfunderkey, compared in time independent of where it first differs.hash_password— The Argon2id hash ofselfunder a new 16-octet salt from the host generator, as a PHC string:$argon2id$v=19$m=19456,t=2,p=1$…$….verify_password— Whetherselfis the passwordhashwas made from, under the hash's own parameters.encrypt— The authenticated encryption ofselfunderkey, withaadbound to it and not encrypted: a new 12-octet nonce from the host generator, then the ciphertext, then the 16-octet tag.decrypt— The plaintext ofselfunderkeyandaad, ornonewhereselfis not an encryption of anything under them: shorter than 28 octets, a changed octet anywhere, a wrong key or a wrongaad.encrypt_to— The age encryption ofselfto every key ofrecipients: any one of their private keys decrypts it.decrypt_with— The plaintext of the age messageselfforidentity, ornonewhere it is not a message to that key or has been changed.encrypt_with_passphrase— The age encryption ofselfunder a passphrase, by age's scrypt recipient with work factor 18.decrypt_with_passphrase— The plaintext of the age messageselfunderpassphrase, ornone.armor— The ASCII armor of an age message:-----BEGIN AGE ENCRYPTED FILE-----.unarmor— The age message an armored text holds, ornone.EncryptedEnd— An endpoint whose writes are age-encrypted torecipientsand stored inendpoint.DecryptedEnd— An endpoint whose contents are those of a replayableendpoint, age-decrypted.DecryptedLive— An endpoint whose contents are those of a liveendpoint, age-decrypted.encrypted_to—endpoint, its writes age-encrypted torecipients.decrypted_with—endpoint, its contents age-decrypted withidentity.