简体   繁体   中英

Twofish encryption implementation using python

I'm trying to encrypt "Hello world" using Twofish algorithm in python. I use this package https://pypi.python.org/pypi/twofish/0.3.0

There's no problem encrypting the message, however I want to set cipher mode to CBC and I don't know how to do it. There's no explanation about how to set cipher mode in document and I can't find the answer when I search in google.

So, have anyone used this package before? and how could you set the cipher mode? please help

This library does not enable you to choose a cypher mode. It is based on libtowfish , and the documentation of the library states (emphahsis is mine) :

void Twofish_encrypt(Twofish_key *xkey, Twofish_Byte plain[16], Twofish_Byte crypto[16]);

Encrypt a single block of data.

This function encrypts a single block of 16 bytes of data. If you want to encrypt a larger or variable-length message, you will have to use a cipher mode, such as CBC or CTR. These are outside the scope of this implementation.

You will need to implement modes yourself (if this is for a serious application, you probably should not), or find a library that does it for you. As far as I know, the main crypto libraries in Python ( PyCryptodome , Cryptography ) does not have twofish implemented.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM