1. 程式人生 > >python AES CFB-128加密

python AES CFB-128加密

1.傳統的pycrypto已經不更新了有很多bug 導致 CFB模式有問題,網上的99%都是錯的,要用pycryptodome

2.包出現問題應該去github看wiki或者bug 搜關鍵詞

3.以下是程式碼

def AES_128_CFB(String):
    cryptor = AES.new(key=key, mode=AES.MODE_CFB, IV=iv,segment_size=128)
    ciphertext = cryptor.encrypt(String)
    return   base64.b64encode(ciphertext)

def AES_128_CFB_decode(String):
    decode = base64.b64decode(String)
    cryptor = AES.new(key=key, mode=AES.MODE_CFB, IV=iv,segment_size=128)
    plain_text = cryptor.decrypt(decode)
    return plain_text

def get_encode_data(message):
    cryptor = AES.new(key=key, mode=AES.MODE_CFB, IV=iv, segment_size=128)
    ciphertext = cryptor.encrypt(message)
    return base64.b64encode(ciphertext)
    # vo = ttypes.EnDecodeVO(key = key,iv = iv,key_algorithm = key_algorithm,default_cipher_algorithm = default_cipher_algorithm,data = message)
    # transport = TSocket.TSocket(thrift_host, thrift_port)
    # transport = TTransport.TFramedTransport(transport)
    # protocol = TBinaryProtocol.TBinaryProtocol(transport)
    # thrift_client = IEnDecodeService.Client(protocol)
    # transport.open()
    # response_data = thrift_client.Encode(vo=vo)
    # return response_data.encode("utf-8")

4.本來是用java開啟一個thrift服務用於加解密的,後來找到問題了改回了python