Beispiel #1
0
    def runTest(self):
        key = RSA.generate(1024)
        hashed = SHA1.new(b("Test"))
        good_signature = PKCS1_PSS.new(key).sign(hashed)
        verifier = PKCS1_PSS.new(key.publickey())

        self.assertEqual(verifier.verify(hashed, good_signature), True)

        # Flip a few bits in the signature
        bad_signature = strxor(good_signature, bchr(1) * len(good_signature))
        self.assertEqual(verifier.verify(hashed, bad_signature), False)
Beispiel #2
0
    def runTest(self):

        key = RSA.generate(1024)
        signer = pkcs1_15.new(key)
        hash_names = ("MD2", "MD4", "MD5", "RIPEMD160", "SHA1",
                      "SHA224", "SHA256", "SHA384", "SHA512",
                      "SHA3_224", "SHA3_256", "SHA3_384", "SHA3_512")

        for name in hash_names:
            hashed = load_hash_by_name(name).new(b("Test"))
            signer.sign(hashed)

        from crypto.Hash import BLAKE2b, BLAKE2s
        for hash_size in (20, 32, 48, 64):
            hashed_b = BLAKE2b.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_b)
        for hash_size in (16, 20, 28, 32):
            hashed_s = BLAKE2s.new(digest_bytes=hash_size, data=b("Test"))
            signer.sign(hashed_s)
def main():
    """主函数"""
    # 生成密钥对
    key_pair = RSA.generate(1024)
    # 导入公钥
    pub_key = RSA.importKey(key_pair.publickey().exportKey())
    # 导入私钥
    pri_key = RSA.importKey(key_pair.exportKey())
    message1 = 'hello, world!'
    # 加密数据
    data = pub_key.encrypt(message1.encode(), None)
    # 对加密数据进行BASE64编码
    message2 = base64.b64encode(data[0])
    print(message2)
    # 对加密数据进行BASE64解码
    data = base64.b64decode(message2)
    # 解密数据
    message3 = pri_key.decrypt(data)
    print(message3.decode())
Beispiel #4
0
 def test_can_sign(self):
     test_public_key = RSA.generate(1024).publickey()
     verifier = pkcs1_15.new(test_public_key)
     self.assertEqual(verifier.can_sign(), False)
Beispiel #5
0
 def test_can_sign(self):
     test_private_key = RSA.generate(1024)
     signer = pkcs1_15.new(test_private_key)
     self.assertEqual(signer.can_sign(), True)
Beispiel #6
0
 def setUp(self):
     self.rng = Random.new().read
     self.key1024 = RSA.generate(1024, self.rng)
Beispiel #7
0
import ast
import time

from crypto import Random
from crypto.PublicKey import RSA
from crypto.Cipher import PKCS1_OAEP

start_time = time.time()
random_generator = Random.new().read

# Generates public and private key
key = RSA.generate(1024, random_generator)

# Exporting public key to global
public_key = key.publickey()

encryptor = PKCS1_OAEP.new(public_key)
pause1 = time.time()

# Choosing file to read

message_file = input('Input filename for reading: ')

with open(message_file, 'r') as message:
    data1 = message.read()
    data1 = str(data1)
    data1 = bytes(data1, 'utf-8')

# Encryption data from read file
continue1 = time.time()
encrypted = encryptor.encrypt(data1)