Demo entry 6751424

py

   

Submitted by lu on Jun 22, 2018 at 15:45
Language: Python. Code size: 1.1 kB.

import Crypto
import random
import random as r
from Crypto import Random
from Crypto.Hash import SHA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
from Crypto.Signature import PKCS1_v1_5 as Signature_pkcs1_v1_5
from Crypto.PublicKey import RSA
import  base64
#密钥的生成
# 伪随机数生成器
elem = Random.new().read
# rsa算法生成实例
rsa1 = RSA.generate(1024,elem)
print(rsa1)
elem1 = str(rsa1)
#公私钥对生成
# 伪随机数生成器
random_generator = Random.new().read
# rsa算法生成实例
rsa = RSA.generate(1024, random_generator)

# master的秘钥对的生成
private_pem1 = rsa.exportKey()

with open('master-private.pem1', 'wb+') as f:
  f.write(private_pem1)
print(private_pem1)
public_pem1 = rsa.publickey().exportKey()
with open('master-public.pem1', 'wb+') as f:
  f.write(public_pem1)
print(public_pem1)

# ghost的秘钥对的生成
private_pem2 = rsa.exportKey()
with open('ghost-private.pem2', 'wb+') as f:
  f.write(private_pem2)
print(private_pem2)
public_pem2 = rsa.publickey().exportKey()
with open('ghost-public.pem2', 'wb+') as f:
  f.write(public_pem2)
print(public_pem2)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).