Compare commits
5
Commits
20e7142e01
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c8e07610d | ||
|
|
c14cfe14b9 | ||
|
|
1b6add1506 | ||
|
|
67176d865c | ||
|
|
edb6709b4b |
@@ -1,38 +0,0 @@
|
|||||||
from cryptography.hazmat.primitives import serialization
|
|
||||||
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
||||||
from cryptography.hazmat.backends import default_backend
|
|
||||||
|
|
||||||
# 生成私钥
|
|
||||||
private_key = rsa.generate_private_key(
|
|
||||||
public_exponent=65537,
|
|
||||||
key_size=2048,
|
|
||||||
backend=default_backend()
|
|
||||||
)
|
|
||||||
|
|
||||||
# 获取公钥
|
|
||||||
public_key = private_key.public_key()
|
|
||||||
|
|
||||||
# 序列化私钥
|
|
||||||
private_pem = private_key.private_bytes(
|
|
||||||
encoding=serialization.Encoding.PEM,
|
|
||||||
format=serialization.PrivateFormat.PKCS8,
|
|
||||||
encryption_algorithm=serialization.NoEncryption()
|
|
||||||
)
|
|
||||||
|
|
||||||
# 序列化公钥
|
|
||||||
public_pem = public_key.public_bytes(
|
|
||||||
encoding=serialization.Encoding.PEM,
|
|
||||||
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
|
||||||
)
|
|
||||||
|
|
||||||
# 保存私钥到文件
|
|
||||||
with open('private_key.pem', 'wb') as f:
|
|
||||||
f.write(private_pem)
|
|
||||||
|
|
||||||
# 保存公钥到文件
|
|
||||||
with open('public_key.pem', 'wb') as f:
|
|
||||||
f.write(public_pem)
|
|
||||||
|
|
||||||
print("RSA密钥对生成成功!")
|
|
||||||
print("私钥已保存到: private_key.pem")
|
|
||||||
print("公钥已保存到: public_key.pem")
|
|
||||||
Reference in New Issue
Block a user