48 位河豚

发布于 2024-08-14 05:16:59 字数 97 浏览 3 评论 0原文

是否有支持 48 位数据块的 Blowfish 算法的实现(Java/C++/Ruby)?我有一个加密问题,输入和输出通道恰好是 48 位。网络上的所有实现都是针对 64 位块的。

Is there an implementation (Java/C++/Ruby) of a Blowfish algorithm that supports 48-bit data blocks? I have an encryption problem where the input and output channels are exactly 48-bits. All implementations on the net are for 64-bit blocks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花开雨落又逢春i 2024-08-21 05:16:59

这是因为 Blowfish 将块大小设置为 64 位。您可以将两个随机字节填充到数据末尾。

require 'rubygems'
require 'crypt/blowfish'
blowfish = Crypt::Blowfish.new("A key up to 56 bytes long")
plain="123456"
encryptedBlock = blowfish.encrypt_block(plain+(rand(250)+5).chr+(rand(250)+5).chr)

或者如果您的 plain 可能小于 6 字节/48 位

encryptedBlock = blowfish.encrypt_block(plain.ljust(8))

That's because Blowfish has a set block size of 64-bits. You could pad two random bytes to the end of your data.

require 'rubygems'
require 'crypt/blowfish'
blowfish = Crypt::Blowfish.new("A key up to 56 bytes long")
plain="123456"
encryptedBlock = blowfish.encrypt_block(plain+(rand(250)+5).chr+(rand(250)+5).chr)

or if your plain could be less than 6 bytes / 48 bits

encryptedBlock = blowfish.encrypt_block(plain.ljust(8))
╰◇生如夏花灿烂 2024-08-21 05:16:59

您可以对河豚使用计数器模式。请记住永远不要重复使用任何反价值。

只需选择一个计数器(它需要在具有相同密钥的所有加密中是唯一的),将计数器填充到 64 位并加密填充的计数器。然后将此加密的前 48 位与明文进行异或以获得密文。对密文重复上述操作即可解密。

唯一的问题是找到合适的计数器。如果将其包含在密文中,则需要超过 48 位。也许你有一个会话 ID 或者你可以使用的东西?

You could use counter-mode with blowfish. Just remember never to reuse any counter-value.

Just select a counter (it will need to be unique across all encryptions with the same key), pad the counter to 64 bits and encrypt the padded counter. Then XOR the first 48 bits of this encryption with your plaintext to gain the ciphertext. Repeat the operation on the ciphertext to decrypt.

The only problem is finding a suitable counter. If you include it with the ciphertext, you need more than 48 bits. Perhaps you have a session-id or something you can use?

爱殇璃 2024-08-21 05:16:59

我建议使用 RC4-drop 1024。RC4 是一种流密码,因此您可以加密任意大小,如果消息小于 48 字节,则可以用空值填充它。 Drop 1024 意味着您丢弃 PRNG 流的前 1024 字节,为此,您可以在第一次使用时加密 1024 字节的垃圾。

BitTorrent 的消息流加密使用 RC4-drop 1024,以下是使用 ARC4 库的 Python 实现:

http://google.com/ codesearch/p?hl=en#4FSOSMZ6Pxc/distfiles/BitTorrent-5.0.7.ta​​r.gz|eyN-AXYL_0E/BitTorrent-5.0.7/BitTorrent/Connector.py&q=lang:python%20%22ARC4.new% 22

I recommend using RC4-drop 1024. RC4 is a stream cipher so you can encrypt an arbitrary size, if the message is less than 48bytes, then you can pad it with nulls. Drop 1024 means you throw away the first 1024 bytes of PRNG stream, to do this you can encrypt 1024 bytes of junk the first time you use it.

BitTorrent's Message Stream Encryption uses RC4-drop 1024 and here is a python implementation using the ARC4 library:

http://google.com/codesearch/p?hl=en#4FSOSMZ6Pxc/distfiles/BitTorrent-5.0.7.tar.gz|eyN-AXYL_0E/BitTorrent-5.0.7/BitTorrent/Connector.py&q=lang:python%20%22ARC4.new%22

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文