简体   繁体   English

使用python实现双鱼加密

[英]Twofish encryption implementation using python

I'm trying to encrypt "Hello world" using Twofish algorithm in python.我正在尝试在 python 中使用 Twofish 算法加密“Hello world”。 I use this package https://pypi.python.org/pypi/twofish/0.3.0我使用这个包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.加密消息没有问题,但是我想将密码模式设置为 CBC,但我不知道该怎么做。 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) :它基于libtowfish ,并且图书馆的文档说明(重点是我的):

void Twofish_encrypt(Twofish_key *xkey, Twofish_Byte plain[16], Twofish_Byte crypto[16]); 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.此函数加密单个 16 字节数据块。 If you want to encrypt a larger or variable-length message, you will have to use a cipher mode, such as CBC or CTR.如果要加密较大的或可变长度的消息,则必须使用密码模式,例如 CBC 或 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.据我所知,Python 中的主要加密库( PyCryptodomeCryptography )没有实现 twofish。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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