def main(): logger.debug("AUGPAKE_SERVER_IP: {}".format(AUGPAKE_SERVER_IP)) logger.debug("AUGPAKE_SERVER_PORT: {}".format(AUGPAKE_SERVER_PORT)) logger.debug("MQTT_BROKER_IP: {}".format(MQTT_BROKER_IP)) logger.debug("MQTT_BROKER_PORT: {}".format(MQTT_BROKER_PORT)) try: ID, Key = getKeyByAugPake(AUGPAKE_SERVER_IP, AUGPAKE_SERVER_PORT) except (OSError, IndexError) as e: logger.error(e) Key = None if Key is None: logger.error("Key is None. Exit...") exit() # create cipher cipher = AESCipher(Key) for line in tailf(WATCH_FILE): logger.debug("Plain Text: {}".format(line)) encrypt_ctx = cipher.encrypt(line) prefix_encrypt = ID + SEP + encrypt_ctx logger.debug("Encrypt Text prefixed ID: {}".format(prefix_encrypt)) publish.single(MQTT_TOPIC, prefix_encrypt, hostname=MQTT_BROKER_IP, port=MQTT_BROKER_PORT)
def __init__(self, serial_key, key_file): self.cipher = CustomCipher() key, public_key, secret_key = self.cipher.init_keys( serial_key, key_file) self.secret_key = secret_key self.public_key = public_key self.serial_key = serial_key self.key = key #print public_key #print secret_key # Ledger initialization aes_cipher = AESCipher() dev1_serial = "Device0001" dev1_serial_hash = hashlib.sha256(dev1_serial.encode()).digest() dev1_pub = aes_cipher.encrypt( RSA.importKey(open("device1-public.pem", "rb")).exportKey('PEM'), dev1_serial_hash) self.blockchain = Chain() self.blockchain.gen_next_block( hashlib.sha256("DeviceAccessBlock1".encode()).digest(), [{ "Serial": dev1_serial, "PubKey": dev1_pub }]) self.ledger = self.blockchain.output_ledger()
def start(self): # read id-pass file cipher = AESCipher(getpass()) try: id, ps = cipher.read_pass() except: print "Cannot read id-pass.txt" exit() browser = webdriver.Chrome(self.DRIVER_PATH) browser.get(self.url) try: # top page block browser.find_element_by_css_selector( "a.btn-03.str-03.str-cv").click() # login page block browser.find_element_by_name("netMemberId").send_keys(id) browser.find_element_by_name("password").send_keys(ps) browser.find_element_by_css_selector( "button.btn-03.str-03.center").click() # needs otp process # displaying charge page block print browser.find_element_by_css_selector("span.num").text # for debug(pause browser) raw_input() finally: browser.quit() """
def test_enrcypted_data_is_decrypted_properly(): aes_cipher = AESCipher(key, IV) input_data = "some data" encrypted_data = aes_cipher.encrypt(input_data) decrypted_data = aes_cipher.decrypt(encrypted_data) assert input_data == decrypted_data
def __init__(self): cipher = AESCipher(getpass()) try: id,ps = cipher.read_pass("gmail-id-pass.txt") except: print "Cannot read id-pass.txt" exit() try: self.gmail = imaplib.IMAP4_SSL("imap.gmail.com") self.gmail.login(id,ps) except: print "Login Failed." return
def read_network_message(self, message): aes_cipher = AESCipher() if self.is_paired: message = self.decrypt(message, self.key) message = ast.literal_eval(message) if all(x in message for x in ["message", "signature", "serial"]): serial = hashlib.sha256(message['serial'].encode()).digest() data = aes_cipher.decrypt(message["message"], serial) signature = message["signature"] if self.cipher.verify(self.network_public_key, serial, data, signature): return data return None
def read_message(self, message): aes_cipher = AESCipher() message = self.cipher.decrypt(message, self.key) message = json.loads(message) if all(x in message for x in ["message", "signature", "serial"]): data = message["message"] signature = message["signature"] serial = message["serial"] secret = hashlib.sha256(serial.encode()).digest() if serial in self.ledger: dec_data = aes_cipher.decrypt(data, secret) pub_key = self.ledger[serial] if self.cipher.verify(pub_key, secret, dec_data, signature): return dec_data return None
def process_network_message(self, data): aes_cipher = AESCipher() if self.is_paired: signature = self.sign(self.key, data) enc_data = aes_cipher.encrypt( data, hashlib.sha256(self.serial_key.encode()).digest()) message = json.dumps({ "message": enc_data, "signature": signature, "serial": self.serial_key }) enc_message = self.encrypt(self.network_serial_key, self.network_public_key, message) return enc_message return None
def __init__(self, pkg_type=constants.PKG_TYPE_HELLO, pkg_num=0, data=b'', password=None): self.pkg_type = pkg_type self.pkg_num = pkg_num self.data = data self.data_length = None self.data_hash = None self.data_length = self.__calculate_data_length__() self.data_hash = self.__calculate_data_hash__() self.password = password if self.password: self.cipher = AESCipher()
def process_access_message(self, serial): aes_cipher = AESCipher() if serial in self.ledger: data = json.dumps({ "type": "response", "serial": self.serial_key, "status": "approved" }) signature = self.sign(self.key, data) enc_data = aes_cipher.encrypt( data, hashlib.sha256(self.serial_key.encode()).digest()) message = json.dumps({ "message": enc_data, "signature": signature, "serial": self.serial_key }) enc_message = self.encrypt(serial, message) return enc_message return None
def DecodePayload(payload): global SESSION_KEY_CACHE global SESSION_CIPHER_CACHE try: ID = payload.decode("utf-8").split(SEP)[0] msg = payload.decode("utf-8").split(SEP)[1] except IndexError as e: logger.error(e) return None if ID not in SESSION_KEY_CACHE: logger.info( "Session key for ID %s is not cached, query by thrift server." % ID) SESSION_KEY_CACHE[ID] = thrift_client.SearchKey(ID) if ID not in SESSION_CIPHER_CACHE: logger.info("Cipher for ID %s is not cached, create one." % ID) SESSION_CIPHER_CACHE[ID] = AESCipher(SESSION_KEY_CACHE[ID]) return SESSION_CIPHER_CACHE[ID].decrypt(msg)
import random import string from aes_cipher import AESCipher key_text = ''.join( [random.choice(string.ascii_letters + string.digits) for i in range(32)]) plain_text = 'test message.' cipher = AESCipher(key_text) encrypted = cipher.encrypt(plain_text) print(encrypted) decrypted = cipher.decrypt(encrypted) print(decrypted) print(decrypted == plain_text)
def __init__(self): self.aes_cipher = AESCipher() self.rsa_cipher = RSACipher()
def __init__(self): self.aes_cipher = AESCipher()
# Client that makes request to a production server import base64 import random import string import requests import json import logging import configs.pentagon as config from aes_cipher import AESCipher cipher = AESCipher(config.AES_PASSPHRASE) def make_request(image, id, daytime, is_last=False): img_path = '/root/Projects/Final_Final/Godfather/cars/' + '{}'.format(daytime) + '_{}'.format(id) + '.jpg' with open(img_path, 'wb') as imgfile: imgfile.write(image) image_string = base64.b64encode(image).decode('utf-8') json_request = {'cookie': config.HTTP_COOKIE, 'image': image_string, 'img_path': img_path} if is_last: json_request['last_image'] = True json_string = json.dumps(json_request) encr_request = cipher.encrypt(json_string) try:
def get_aes_cipher(): return AESCipher(AES_KEY.decode("hex"), AES_IV.decode("hex"))
from flask import Flask, request, jsonify from aes_cipher import AESCipher from os import urandom key = urandom(16) aes = AESCipher(key) app = Flask(__name__) @app.route('/encrypt', methods=['POST']) def encrypt(): try: data = request.get_json() for i in range(len(data['data'])): encrypt_data = aes.encrypt(data['data'][i]['text']) data['data'][i] = {"encrpyted" : encrypt_data} return jsonify(data) except: return jsonify({"message": "Something went wrong, please try again."}),400 @app.route('/decrypt', methods=['POST']) def decrypt(): try: data = request.get_json() for i in range(len(data['data'])): decrypt_data = aes.decrypt(data['data'][i]['encrpyted']) print(decrypt_data) data['data'][i] = {"text" : decrypt_data} return jsonify(data) except: return jsonify({"message": "Something went wrong, please try again."}),400
'cancel_transfer_from_savings_operation': op_cancel_transfer_from_savings, 'decline_voting_rights_operation': op_decline_voting_rights, 'create_proposal_operation': op_create_proposal, 'remove_proposal_operation': op_remove_proposal, 'update_proposal_votes_operation': op_update_proposal_votes, 'claim_reward_balance2_operation': op_claim_reward, 'vote2_operation': op_vote, 'proposal_pay_operation': op_proposal_pay, 'interest_operation': op_interest, 'fill_vesting_withdraw_operation': op_fill_vesting_withdraw, 'fill_order_operation': op_fill_order, 'shutdown_witness_operation': op_shutdown_witness, 'producer_reward_operation': op_producer_reward, 'request_account_recovery_operation': op_request_account_recovery, 'custom_operation': op_custom, 'limit_order_create2_operation': op_limit_order_create, 'limit_order_cancel2_operation': op_limit_order_cancel, 'account_update2_operation': op_account_update2 } cipher = AESCipher(input()) def anonymize(op): if op['type'] not in dispatcher.keys(): with open('not_anonymized.txt', 'ab') as f: f.write(json.dumps(op).encode('utf-8')) f.write('\n'.encode('utf-8')) op['value'] = dispatcher[op['type']](op['value']) return op
def test_given_null_key_or_iv_when_decrpyting_then_error_is_raised(): with raises(AttributeError): AESCipher(None, IV) with raises(AttributeError): AESCipher(key, None)