コード例 #1
0
ファイル: derivation.py プロジェクト: erose1337/crypto
def derive_public_key(private_key):  
    pre_public_key = []
    for byte in range(256):
        message = bytearray(8)
        message[0] = byte
        ciphertext = homomorphic_encrypt(message, private_key, bytearray(sha256(private_key + message + "pre_public").digest()))
        pre_public_key.append(bytes_to_words(ciphertext, 4))
        
    public_key = []
    for byte in range(256):
        message = bytearray()
        message.append(byte)        
        ciphertext = encrypt(message, pre_public_key, prng=lambda amount: random(amount, private_key, chr(byte)))[0] # encrypt returns a list with 1 ciphertext in it    
        public_key.append(bytes_to_words(ciphertext, 4))    
    return public_key
コード例 #2
0
ファイル: publickey_crypt.py プロジェクト: tml/crypto_intro
def encrypt_file(filename, keyfile, crypted_filename = None, 
                 ascii_armour = False):
    if not crypted_filename:
        crypted_filename    = filename + '.rsa'

    plaintext               = load(filename)
    key                     = publickey.load_key(keyfile)
    ciphertext              = publickey.encrypt(key, plaintext)

    if not ascii_armour:
        ciphertext          = '\x00' + ciphertext
    else:
        ciphertext          = 'A' + base64.encodestring(ciphertext)

    print '[+] encrypted %s to %s...' % (filename, crypted_filename)
    dump(crypted_filename, ciphertext)
    print '[+] file written...'
コード例 #3
0
ファイル: publickey_tests.py プロジェクト: tml/crypto_intro
def test_crypto():
    message = 'This is a test message. 0123456789ABCDEF'
    print '\t[+] generating a 2048-bit RSA key... ',
    flush()
    key     = publickey.generate_key( 2048 )
    assert( key.size() == 2047 )
    print 'OK!'

    print '\t[+] can we encrypt with this key? ',
    flush()
    assert( key.can_encrypt() )
    print 'yes'

    print '\t[+] encrypting \'%s\'...' % message
    print '\t[+] using %d-bit RSA key' % (key.size() + 1)

    ct      = publickey.encrypt( key, message )
    pt      = publickey.decrypt( key, ct )

    print '\t[+] decryped ciphertext as \'%s\'' % pt
    assert( pt == message )
コード例 #4
0
ファイル: derivation.py プロジェクト: overgter/crypto
def derive_public_key(private_key):
    pre_public_key = []
    for byte in range(256):
        message = bytearray(8)
        message[0] = byte
        ciphertext = homomorphic_encrypt(
            message, private_key,
            bytearray(sha256(private_key + message + "pre_public").digest()))
        pre_public_key.append(bytes_to_words(ciphertext, 4))

    public_key = []
    for byte in range(256):
        message = bytearray()
        message.append(byte)
        ciphertext = encrypt(
            message,
            pre_public_key,
            prng=lambda amount: random(amount, private_key, chr(byte)))[
                0]  # encrypt returns a list with 1 ciphertext in it
        public_key.append(bytes_to_words(ciphertext, 4))
    return public_key