| CARVIEW |
Select Language
HTTP/2 200
date: Mon, 29 Dec 2025 08:57:07 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"67a212d925bafdb60934a96fae44ca19"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=qDv556ONz8erF7t4TGs195k7mS8%2BfONjqRmhBBY7HPtwjSFiSIlvF4kW6hIL4%2FyOBhb2RAJ1xFYStlsyyCibJCCvB9G5aZFvq13n2PM4CXncaK2qJpxDaiRlw%2BMoWGbNbLZdAubyDqjCkjiLTIR4vQF17%2F5rXMaSSo1vJfCDUc6hiusToPmy0twaxbKo2nriIUu%2FjmeAGH5ysfu8Rc%2FFNj7PC9k5Wc%2BsHKVEFCkAoS0G8%2FtEwOAFt1GJMWp2KkA0cQGhaJ%2FOJ8uSvjkJ6lPkqQ%3D%3D--kt5Tq2thNgpzT8tZ--W4HbcjdaYFuqwotrB%2FHuNg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1725673641.1766998627; Path=/; Domain=github.com; Expires=Tue, 29 Dec 2026 08:57:07 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Tue, 29 Dec 2026 08:57:07 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: D826:3A7CC8:5C72790:6F7D636:69524262
Code Examples · aabmets/quantcrypt Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 9
Code Examples
Mattias Aabmets edited this page Mar 16, 2025
·
6 revisions
from quantcrypt.kem import MLKEM_1024
# First, we create an instance of a KEM algorithm.
kem = MLKEM_1024()
# Next, we generate a PK and SK pair.
public_key, secret_key = kem.keygen()
# Then, we use the PK to encapsulate the internally
# generated shared_secret bytes into cipher_text bytes.
cipher_text, shared_secret = kem.encaps(public_key)
# Finally, the secret_key is used to decapsulate the
# original shared_secret from the cipher_text bytes.
shared_secret_copy = kem.decaps(secret_key, cipher_text)
# Check that the shared secrets match
assert shared_secret_copy == shared_secretfrom quantcrypt.dss import MLDSA_87
# First, we create an instance of a DSS algorithm
# and also define a message to be signed.
dss = MLDSA_87()
message = b'Hello World'
# Next, we generate a PK and SK pair.
public_key, secret_key = kem.keygen()
# Then, we use the secret_key to sign the message.
signature = dss.sign(secret_key, message)
# Finally, we use the public_key to verify the validity of the signature.
dss.verify(public_key, message, signature)from pathlib import Path
from quantcrypt.dss import MLDSA_87
# First, we create an instance of a DSS algorithm
# and obtain a path to the file to be signed.
dss = MLDSA_87()
file_path = Path("/absolute/path/to/target/file.any")
# Next, we generate a PK and SK pair.
public_key, secret_key = kem.keygen()
# Then, we use the secret_key to sign the file.
signed_file = dss.sign_file(secret_key, file_path)
# Finally, we use the public_key to verify the validity of the signature.
dss.verify_file(public_key, file_path, signed_file.signature)import secrets
from quantcrypt.cipher import Krypton
# Krypton requires the symmetric secret key to be 64 bytes long.
secret_key = secrets.token_bytes(64)
plaintext = b"Hello World"
krypton = Krypton(secret_key)
# Encrypt the plaintext and generate the verification data packet.
krypton.begin_encryption()
ciphertext = krypton.encrypt(plaintext)
verif_dp = krypton.finish_encryption()
# Decrypt the plaintext and verify its validity in finish_decryption call.
krypton.begin_decryption(verif_dp)
plaintext_copy = krypton.decrypt(ciphertext)
krypton.finish_decryption()
assert plaintext_copy == plaintextimport secrets
from pathlib import Path
from quantcrypt.cipher import KryptonFile
# Krypton requires the symmetric secret key to be 64 bytes long.
secret_key = secrets.token_bytes(64)
# The plaintext file, which must exist, can be of any type and any size.
plaintext_file = Path("/absolute/path/to/plaintext_file.any")
# If the ciphertext_file exists, it will be overwritten.
ciphertext_file = Path("/absolute/path/to/ciphertext_file.any")
# Create a Krypton instance with the secret key and encrypt the
# plaintext file contents into the designated ciphertext file.
krypton = KryptonFile(secret_key)
krypton.encrypt(plaintext_file, ciphertext_file)
# The ciphertext file can be decrypted into another file or into memory.
# Note: Do not decrypt huge files into memory, use your best judgement.
plaintext_file_copy = Path("/absolute/path/to/plaintext_file_copy.any")
krypton.decrypt_to_file(ciphertext_file, plaintext_file_copy)
plaintext_data = krypton.decrypt_to_memory(ciphertext_file)from pathlib import Path
from quantcrypt.kem import MLKEM_1024
from quantcrypt.cipher import KryptonKEM
# First we instantiate the KEM algorithm to generate a keypair.
kem = MLKEM_1024()
public_key, secret_key = kem.keygen()
# We need to provide KryptonKEM with the class of the
# KEM algorithm which was used to generate the keypair.
krypton = KryptonKEM(MLKEM_1024)
# The plaintext file, which must exist, can be of any type and any size.
plaintext_file = Path("/absolute/path/to/plaintext_file.any")
# If the ciphertext_file exists, it will be overwritten.
ciphertext_file = Path("/absolute/path/to/ciphertext_file.any")
# Use the public_key to encrypt the plaintext file
# contents into the designated ciphertext file.
krypton.encrypt(public_key, plaintext_file, ciphertext_file)
# Use the secret_key to decrypt the ciphertext file into another file or into memory.
# Note: Do not decrypt huge files into memory, use your best judgement.
plaintext_file_copy = Path("/absolute/path/to/plaintext_file_copy.any")
krypton.decrypt_to_file(secret_key, ciphertext_file, plaintext_file_copy)
plaintext_data = krypton.decrypt_to_memory(secret_key, ciphertext_file)from quantcrypt.kdf import Argon2
strong_password = "A8c7hBBTnVC90kP5AIe2"
# Generate the hash of the users password to be stored into a database
a1 = Argon2.Hash(strong_password)
# Verify the login password with the password hash from the database
a2 = Argon2.Hash(strong_password, a1.public_hash)
assert a2.verified is True
# Argon2 asserts user password strength with the zxcvbn library.
# The following line raises quantcrypt.errors.KDFWeakPasswordError:
Argon2.Hash("my_weak_password")
# You can disable the password minimum strength check:
Argon2.Hash("my_weak_password", min_years=0)
Argon2.Hash(b"my_weak_password") # bytesimport secrets
from quantcrypt.kdf import Argon2
from quantcrypt.cipher import Krypton
secret_key = secrets.token_bytes(32)
# Expand a 32 byte secret key into a 64 byte secret key:
argon = Argon2.Key(secret_key)
# Use the 64 byte secret key to key the Krypton cipher:
krypton = Krypton(argon.secret_key)import secrets
from quantcrypt.kdf import KKDF
# Obtain a master secret key
secret_key = secrets.token_bytes(64)
# Derive the keys
keys = KKDF(
master=secret_key,
key_len=64,
num_keys=1
)
# Sanity check
assert isinstance(keys, tuple)
assert isinstance(keys[0], bytes)
assert len(keys[0]) == 64Clone this wiki locally
You can’t perform that action at this time.