示例#1
0
    def test_encrypt_decrypt(self):
        data = "encrypted decrypted \n data1"
        key = b'1234567890123456'

        encrypted = encryptor.encrypt(key,data)
        decrypted = encryptor.decrypt(key,encrypted)

        self.assertEqual(decrypted,data)
示例#2
0
def load():
    try:
        file = open(os.getcwd() + "/prop.prp", "r+")
    except FileNotFoundError:
        print("Not founded")
        return NullProperties()
    lines = file.readlines()
    if (len(lines) < 2):
        print("Not enough")
        file.close()
        return NullProperties()
    file.close()
    silM = False
    if (encryptor.decrypt(lines[0][:-1]) == "True"):
        silM = True
    adres = encryptor.decrypt(lines[1][:-1])
    size = int(encryptor.decrypt(lines[2][:-1]))
    return Properties(silM, adres, size)
示例#3
0
    def read(self, path, length, offset, fh):
        fh.seek(offset)
        enc = fh.read(length) # Get the data

        # Get information from metadata for Custos
        cuuid = self.externdata['cuuid']
        suuid = self.externdata['suuid']

        # Actually decrypt the data
        dec = decrypt(enc, offset, fh, cuuid, suuid)
        return dec
示例#4
0
    def test_secret_encryption(self):
        assert conf.get(ENCRYPTION_KEY) == 'my_key'
        assert conf.get(ENCRYPTION_SECRET
                        ) == 'qMGwKR21SAjprV0XOJUI4SoI-MLFoTxN1ahZndKREL4='
        encryptor.validate()
        encryptor.setup()

        value = 'foo'
        encrypted_value = encryptor.encrypt(value)

        assert encrypted_value.startswith('{}my_key$'.format(
            EncryptionManager.MARKER))
        assert encryptor.decrypt(encrypted_value) == 'foo'
def receive():
    while True:
        try:
            received_message = client.recv(1024).decode('utf-8')
            sender_nickname, encrypted_message = received_message.split(' ', 1)

            if sender_nickname == 'server':
                if encrypted_message.isdigit():
                    decrypted_message = int(encrypted_message)
                else:
                    decrypted_message = encrypted_message
            else:
                decrypted_message = decrypt(int(encrypted_message),
                                            private_key, N)
                decrypted_message = numeric_cipher_to_text(
                    str(decrypted_message))

            if sender_nickname == 'server':
                if decrypted_message == 1:
                    client.send(nickname.encode('utf-8'))
                elif decrypted_message == 2:
                    client.send(str(public_key).encode('utf-8'))
                elif decrypted_message == 3:
                    client.send(str(N).encode('utf-8'))
                else:
                    print(f"[{decrypted_message}]")

            else:
                print(f"{sender_nickname.capitalize()}: {decrypted_message}")

        except Exception as e:
            global is_running
            if is_running == False:
                break
            elif is_running == True:
                client.send("leave".encode('utf-8'))

                client_data_partial = {}
                with open("data.pickle", "rb") as f:
                    print(f)
                    client_data_partial = pickle.load(f)

                client_data_partial.pop(nickname.lower())

                with open("data.pickle", "wb") as f:
                    pickle.dump(client_data_partial, f)

                is_running = False

            print(f"An error has Occured: {e}")
            break
示例#6
0
    def write(self, path, buf, offset, fh):
        fh.seek(0, 0)

        self.externdata['size'] += len(buf)

        # Get information from metadata for Custos
        cuuid = self.externdata['cuuid']
        suuid = self.externdata['suuid']
        # Decrypt the data
        dec = decrypt(fh.read(), 0, fh, cuuid, suuid)
        enc_size = encrypt(dec+buf, 0, fh, cuuid, suuid)

        #return enc_size
        return len(buf)
示例#7
0
def test1(correct_output, offset=0):
    fd, temp_path = tempfile.mkstemp()
    os.remove(temp_path)
    fh = os.fdopen(fd, 'w+')

    uuid = 0
    server = "server"

    encrypt(correct_output, 0, fh, uuid, server)
    fh.seek(0, os.SEEK_END)
    enc_len = fh.tell()
    fh.seek(0, os.SEEK_SET)
    dec = decrypt(fh.read(enc_len), 0, True, uuid, server)

    if (dec != correct_output):
        sys.exit(1)
示例#8
0
    if message == 'Goodbye':
        c.send("okay".encode())
    else:
        key = message
        print('Key received!\n')
        c.send("Thanks for the key!".encode())
else:
    c.send("okay".encode())

while True:

    sock.listen(5)
    print("the server is listening...\n")

    c, addr = sock.accept()
    print("Connection established")

    message = c.recv(1024).decode()
    print("Message received")
    print("It is: " + message)

    decryMsg = decrypt(key, message)
    encryMsg = encrypt(key, decryMsg)

    c.send(encryMsg.encode())

    print("Response sent\n")

c.close()
sock.close()
示例#9
0
 def to_python(self, value):
     if value is not None and isinstance(value, str):
         value = encryptor.decrypt(value)
     return super().to_python(value)
示例#10
0
if __name__ == '__main__':
    # parse the arguments
    parser = argparse.ArgumentParser(description='Secure your file system')

    parser.add_argument('option', help='encrypt or decrypt')
    parser.add_argument('path', help='path to target file')

    args = parser.parse_args()

    # get the password
    password = getpass.getpass('Password: '******'Retype password: '******'Passwords don\'t match!')
        exit(0)

    # encrypt
    if args.option.lower() == 'encrypt':
        encryptor.encrypt(args.path, password)

    # decrypt
    elif args.option.lower() == 'decrypt':
        encryptor.decrypt(args.path, password)

    # invalid
    else:
        show_usage()
示例#11
0
def getBotData():
    with open("version.json", "r") as f:
        j = json.loads(f.read())
        username = j["username"]
        pas = str(encryptor.decrypt(str.encode(j["password"])), 'utf-8')
        return username, pas
示例#12
0
    def test_default_encryption(self):
        assert conf.get(ENCRYPTION_KEY) is None
        assert conf.get(ENCRYPTION_SECRET) is None

        assert encryptor.encrypt('foo') == 'foo'
        assert encryptor.decrypt('foo') == 'foo'