Beispiel #1
0
def sign(modulus, exponent, private_exp, message):
    if RSA:
        rsa = RSA((modulus, exponent, private_exp))
        result = rsa._sign(message)
        return result[0]
    else:
        return ''
Beispiel #2
0
    def to_power_modulo1(self, base, power, modulo):
        return base**power % modulo

    def encrypt(self, T):
        #en = T**self.e % self.n
        #en = self.to_power_modulo(T, self.e, self.n)
        public_key = key.publickey()
        enc_data = public_key.encrypt(T, 32)
        if self.debug:
            print "encrpted: %d" % en
            print
        return en

    def decrypt(self, C):
        #dec = C**self.d % self.n
        #dec = self.to_power_modulo(C, self.d, self.n)
        key.decrypt(C)
        if self.debug:
            print "decrypted: %d" % dec
            print
        return dec


if __name__ == '__main__':
    r = RSA()
    '''
    data = 56567
    enc = r.encrypt(data)
    r.decrypt(enc)
    '''
Beispiel #3
0
def verify(modulus, exponent, message, signature):
    if RSA:
        rsa = RSA((modulus, exponent))
        return rsa._verify(message, signature)
    else:
        return True
    publickey = key.publickey  # pub key export for exchange

    encrypted = publickey.encrypt('encrypt this message', 32)
    # message to encrypt is in the above line 'encrypt this message'

    print
    'encrypted message:', encrypted  # ciphertext

    f = open('encryption.txt', 'w')
    f.write(str(encrypted))  # write ciphertext to file
    f.close()

    # decrypted code below

    f = open('encryption.txt', 'r')
    message = f.read()

    decrypted = key.decrypt(message)

    print
    'decrypted', decrypted

    f = open('encryption.txt', 'w')
    f.write(str(message))
    f.write(str(decrypted))
    f.close()


if __name__ == '__main__':
    RSA()
Beispiel #5
0
 def random(cls):
     return RSA(*cls.generate_key_pair())
Beispiel #6
0
#
# by Daniel Mendyke [[email protected]], Aug 19, 2018
#

#
# Requied Modules
from randorg import Integers
from Crypto.PublicKey import RSA


#
# Generate RSA keys from random.org
class RSA(object):

    KEY = "1b1ab23b-c138-40f2-99d7-d09e3319d332"

    #
    # Constructor
    def __init__(self):

        value = Integers(RSA.KEY, id=1, num=3, min=0)
        private_key = RSA.construct((value[0], value[1], value[2]))
        public_key = private_key.publickey()

        print(private_key)
        print(public_key)


if __name__ == "__main__":
    rsa = RSA()