web>app
This commit is contained in:
33
main.py
33
main.py
@@ -3,6 +3,8 @@ import base64
|
||||
import uuid
|
||||
import string
|
||||
import pyperclip
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa, ec
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
import customtkinter as ctk
|
||||
from tkinter import messagebox
|
||||
|
||||
@@ -10,6 +12,8 @@ ctk.set_appearance_mode("dark")
|
||||
ctk.set_default_color_theme("blue")
|
||||
|
||||
KEY_TYPES = [
|
||||
("JWT Key Pair (RS256)", "jwt_rs256", "RSA 2048-bit · PEM", 256, "rsa_keypair"),
|
||||
("JWT Key Pair (ES256)", "jwt_es256", "EC P-256 · PEM", 32, "ec_keypair"),
|
||||
("JWT Secret (HS256)", "jwt_hs256", "32 bytes · Hex", 32, "hex"),
|
||||
("JWT Secret (HS384)", "jwt_hs384", "48 bytes · Hex", 48, "hex"),
|
||||
("JWT Secret (HS512)", "jwt_hs512", "64 bytes · Hex", 64, "hex"),
|
||||
@@ -34,6 +38,32 @@ FORMAT_MAP = {
|
||||
|
||||
|
||||
def generate_key(byte_length: int, fmt: str) -> str:
|
||||
if fmt == "rsa_keypair":
|
||||
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
|
||||
priv_pem = private_key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PrivateFormat.PKCS8,
|
||||
encryption_algorithm=serialization.NoEncryption(),
|
||||
).decode()
|
||||
pub_pem = private_key.public_key().public_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
||||
).decode()
|
||||
return priv_pem + "\n" + pub_pem
|
||||
|
||||
if fmt == "ec_keypair":
|
||||
private_key = ec.generate_private_key(ec.SECP256R1())
|
||||
priv_pem = private_key.private_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PrivateFormat.PKCS8,
|
||||
encryption_algorithm=serialization.NoEncryption(),
|
||||
).decode()
|
||||
pub_pem = private_key.public_key().public_bytes(
|
||||
encoding=serialization.Encoding.PEM,
|
||||
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
||||
).decode()
|
||||
return priv_pem + "\n" + pub_pem
|
||||
|
||||
raw = secrets.token_bytes(byte_length)
|
||||
if fmt == "hex":
|
||||
return raw.hex()
|
||||
@@ -301,8 +331,9 @@ class App(ctk.CTk):
|
||||
self._key_box.insert("1.0", key)
|
||||
self._key_box.configure(state="disabled")
|
||||
|
||||
fmt_display = {"rsa_keypair": "RS256", "ec_keypair": "ES256"}.get(fmt, fmt.upper())
|
||||
self._meta_label.configure(
|
||||
text=f"{entry[0]} · {bits}-bit · {fmt.upper()} · {len(key)} chars"
|
||||
text=f"{entry[0]} · {bits}-bit · {fmt_display} · {len(key)} chars"
|
||||
)
|
||||
|
||||
# Reset copy button
|
||||
|
||||
Reference in New Issue
Block a user