importbase64fromcryptography.hazmat.primitivesimportserializationfromcryptography.hazmat.primitives.asymmetricimported25519defgenerate_ed25519_keypair(private_key_filename:str="private.key",public_key_filename:str="public.pub")-> None:"""Generate Ed25519 Keys Pairs. Args: private_key_filename(default private.key): private key filename as a string. public_key_filename(default public.pub): public key filename as a string Returns: """private_key=ed25519.Ed25519PrivateKey.generate()public_key=private_key.public_key()private_key_str=private_key.private_bytes(encoding=serialization.Encoding.Raw,format=serialization.PrivateFormat.Raw,encryption_algorithm=serialization.NoEncryption(),)print("Private Key:\t",base64.urlsafe_b64encode(private_key_str))public_key_str=public_key.public_bytes(encoding=serialization.Encoding.Raw,format=serialization.PublicFormat.Raw)print("Public Key:\t",base64.urlsafe_b64encode(public_key_str))withopen(private_key_filename,"wb")asfp:fp.write(base64.urlsafe_b64encode(private_key_str))print(f"Private Key is written to:\t{private_key_filename}")withopen(public_key_filename,"wb")asfp:fp.write(base64.urlsafe_b64encode(public_key_str))print(f"Public Key is written to:\t{public_key_filename}")
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-30。"],[],[]]