예제 #1
0
def decrypt(ciphertext):
    key = POWERSHADE_PRESHARED_KEY
    key = key[:32]
    aescrypto = crypto.AESCipher(key)
    plaintext = aescrypto.decrypt(ciphertext)
    plaintext = zlib.compress(plaintext)
    return plaintext
예제 #2
0
def encrypt(plaintext):
    compressedtxt = zlib.compress(plaintext)
    key = POWERSHADE_PRESHARED_KEY
    key = key[:32]
    aescrypto = crypto.AESCipher(key)
    ciphertext = aescrypto.encrypt(compressedtxt)
    return ciphertext
예제 #3
0
 def trigger(self, token=''):
     if (len(token) > 0):
         #print "trigger() Len(token): ", str(len(token))
         key = POWERSHADE_PRESHARED_KEY
         key = key[:32]
         aescrypto = crypto.AESCipher(key)
         plaintext = aescrypto.decrypt(token)
         plaintext = zlib.decompress(plaintext)
         #print "trigger(): Message ",plaintext
         mode, salt = plaintext.split(':')
         return changeConfigMode(mode)
예제 #4
0
 def __init__(self, stream, hkey=None):
     self.stream = stream
     self.crypto_helper = crypto.AESCipher()  
     
     if hkey is not None:
         self.hkey = hkey
     else:
         raise AttributeError("Must Supply an HMAC Key <self.hkey> to object initialization")
     
     self.sha256 = None
     #self.sha256 = hmac.HMAC(key=self.hkey, digestmod="SHA256")
     return
예제 #5
0
def encrypt(K: bytes, X, T):
    assert check_config_file()
    if not 2 <= config.RADIX <= 2**16:
        raise InvalidRadixException

    X = str(X)
    T = str(T)
    assert len(X) > 0, error.ErrorHandler.ERROR_EMPTY_MESSAGE
    n = len(X)
    t = len(T)
    u = math.floor(n / 2)
    v = n - u
    A = X[0:u]
    B = X[u:n]
    assert len(A) + len(B) == n, error.ErrorHandler.ERROR_FEISTEL_MESSAGE_LENGTH
    b = math.ceil(math.ceil(v * math.log(config.RADIX, 2)) / 8)
    d = 4 * int((b+3)/4)
    P = generate_p(u % 256, n, t)
    log.print_array(P, "P")
    bmagnitude = 10 ** int((n+1)/2)
    for i in range(0, ROUNDS):
        log.print_round(i)
        log.print_b(B)
        Q = generate_q(T, i, B, b)
        log.print_array(Q, "Q")

        to_encrypt = P + Q

        AES = crypto.AESCipher(K)
        R = AES.encrypt(to_encrypt)[-16:]
        log.print_array(R, "R")

        S = R[:d+4]
        y = int.from_bytes(S, byteorder='big')

        if isEven(i):
            m = u
        else:
            m = v

        c = (num_radix(A) + y) % (config.RADIX ** m)
        C = str(c)
        A = B
        B = C
        log.print_sides(A, B)

    return str(int(A) * bmagnitude + int(B))
def editwhiteip_url(seq):
    _pattern = db_session.query(Integrated_IPS_Management).filter_by(
        seq=seq).first()
    try:
        _pattern.IPS_Name = request.form['IPS_Name'].strip()
        _pattern.IP_Address = request.form['IP_Address'].strip()
        _pattern.Description = request.form['Description'].strip()
        c = crypto.AESCipher()
        encryptedValue = c.encrypt(request.form['Password'].strip())
        _pattern.Password = encryptedValue
        # _pattern.description = request.form['desc']
        # _pattern.mod_dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

        db_session.commit()
    except Exception as e:
        db_session.rollback()
        raise InvalidUsage('DB 저장 오류', status_code=501)
    return ""
def addwhiteip_url():
    #exists = Integrated_IPS_Management.query.filter_by(ip=request.form['pattern'].strip()).first()
    # if exists is not None:
    #     raise InvalidUsage('중복 IP가 존재합니다.', status_code=501) # duplication is allowed.

    try:
        _pattern = Integrated_IPS_Management()
        _pattern.IPS_Name = request.form['IPS_Name']
        _pattern.IP_Address = request.form['IP_Address'].strip()
        _pattern.Description = request.form['Description'].strip()
        c = crypto.AESCipher()
        encryptedValue = c.encrypt(request.form['Password'].strip())
        _pattern.Password = encryptedValue
        # _pattern.description = request.form['desc']
        db_session.add(_pattern)
        db_session.commit()
    except Exception as e:
        db_session.rollback()
        raise InvalidUsage('DB 저장 오류', status_code=501)

    return ""
예제 #8
0
    def _setup(self):
        self.key = crypto.generate_random(self.sec_size)
        #self.random_x = int.from_bytes(crypto.generate_random(self.sec_size), byteorder='big') % self.slots_length

        for i in range(0, self.number):
            self.slots[i] = "1"

        #self.shuffled_slots = self.slots
        #random.seed(os.urandom(self.sec_size))
        #random.shuffle(self.shuffled_slots)

        #picked = False
        #while not picked:
        #    slot = random.randint(0, self.slots_length)
        #    if self.shuffled_slots[slot] == '1':
        #        picked = True
        #        self.pi_x = slot

        for i in range(0, self.slots_length):
            self.slots_keys[i] = crypto.generate_random(self.sec_size)
            aes = crypto.AESCipher(self.slots_keys[i])
            self.shuffled_slots[i] = str(
                int.from_bytes(aes.encrypt(self.shuffled_slots[i]), 'big'))
예제 #9
0
 def __init__(self, collection, context, key):
     super(TokenStore, self).__init__(collection, context)
     self._cipher = crypto.AESCipher(key)
     self._tokens = {self._cipher.decrypt(enc): enc for enc in self.keys()}