parent
							
								
									6fe5b455e2
								
							
						
					
					
						commit
						055fe16538
					
				| @ -0,0 +1,23 @@ | ||||
| import os | ||||
| from Crypto.PublicKey import RSA | ||||
| 
 | ||||
| def B_key(): | ||||
|     # 生成密钥对 | ||||
|     key = RSA.generate(2048) | ||||
| 
 | ||||
|     # 获取私钥和公钥 | ||||
|     private_key = key.export_key() | ||||
|     public_key = key.publickey().export_key() | ||||
| 
 | ||||
|     # 获取当前文件的目录路径 | ||||
|     current_directory = os.path.dirname(__file__) | ||||
| 
 | ||||
|     # 保存私钥到文件(相对路径) | ||||
|     private_file_path = os.path.join(current_directory, 'B_private.txt') | ||||
|     with open(private_file_path, 'wb') as private_file: | ||||
|         private_file.write(private_key) | ||||
| 
 | ||||
|     # 保存公钥到文件(相对路径) | ||||
|     public_file_path = os.path.join(current_directory, 'B_public.txt') | ||||
|     with open(public_file_path, 'wb') as public_file: | ||||
|         public_file.write(public_key) | ||||
					Loading…
					
					
				
		Reference in new issue