def test_encrypt_and_decrypt(self): alice = secp256k1.make_keypair() bob = secp256k1.make_keypair() raw_text = "快使用双节棍呵呵哈黑" enc = alice.publicKey.encrypt(bob.privateKey, raw_text.encode(), raw=True) print("enc:%s" % enc) res = bob.privateKey.decrypt(alice.publicKey, enc['enc'], None) self.assertEqual(raw_text, res)
def test_generate_secret(self): for i in range(100): alice = secp256k1.make_keypair() alice_pub = secp256k1.PublicKey.restore("%s" % alice.publicKey) alice_pri = secp256k1.PrivateKey.restore("%s" % alice.privateKey) bob = secp256k1.make_keypair() bob_pub = secp256k1.PublicKey.restore('%s' % bob.publicKey) bob_pri = secp256k1.PrivateKey.restore('%s' % bob.privateKey) secret1 = alice_pri.generate_secret(bob_pub) secret2 = bob_pri.generate_secret(alice_pub) self.assertEqual(secret1, secret2)
def test_make_keypair(self): kp = secp256k1.make_keypair() str_pub = "%s" % kp.publicKey str_pri = "%s" % kp.privateKey print('pub: %s' % str_pub) print('pri: %s' % str_pri) pub = secp256k1.PublicKey.restore(str_pub) self.assertEqual(kp.publicKey.Q, pub.Q)
def test_encrypt(self): raw_txt = "哇卡里马戏打" pubKey = secp256k1.PublicKey.restore( '02be8d8a7b5056de7a7074236100d094ebe86cce33d62469956203022af1f3e556' ) me = secp256k1.make_keypair() encrypted = pubKey.encrypt(me.privateKey, raw_txt.encode('utf8'), raw=True) data_arr = bytearray(str(me.publicKey).encode()) data_arr.extend(encrypted['enc']) b64_str = base64.urlsafe_b64encode(data_arr).decode() print(f"message:{b64_str}")
from rsa import common, transform, core from rsa.pkcs1 import _pad_for_signing from ecdsa import SigningKey import time from hashlib import sha256 import json import logging from typing import Dict, List from secp256k1py import secp256k1 length = 128 global p,q,g,n,i,SKlist,PKlist,rlist,CHpublic,CHprivate,r1 p,q,g = 0,0,0 ChSign_public_key, ChSign_private_key = myrsa.newkeys() global KeySPEC KeySPEC=secp256k1.make_keypair() global public_value,tn_scrtklist,tn_pubklist,value_scale,t_value,tn_users,total_CH_S,total_CH_PB global secret_poly_list,result_list,Si_list public_value,tn_scrtklist,tn_pubklist = [],[],[] secret_poly_list,result_list,Si_list = [],[],[] value_scale = 100 random.randint(1,1000) primelist = [] for i in range(1000): if is_prime(i)==True: primelist.append(i) ChSign_public_key, ChSign_private_key = myrsa.newkeys() def primeFactorization(k):#分解质因数 while True: q=get_large_prime_length(length)