如何在 Java 中使用 Skipjack (skip32) 随机化数据库中的连续整数
根据上一个问题,我正在使用连续整数作为我的数据库中的记录 ID。我想使用 Skip32 来混淆整数 ID。我找到了 Java 实现,但我不确定如何使用标准 JCE API 对其进行初始化。我需要加密一个整数并根据需要解密它。谁能给我举个例子吗?
Based on a previous question, I am using a sequential integer as a record ID in my database. I want to obfuscate the integer IDs using Skip32. I found a Java implementation but I am uncertain of how to initialize it using the standard JCE APIs. I need to encrypt an integer and decrypt it as necessary. Can anyone show me an example of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您找到的代码属于 Cryptix 项目。您不仅需要这一个文件,还应该获取整个包。获取 JCE 包,将其安装为提供程序。那么你应该能够使用
但实际上,不要使用像 Cryptix 这样不受支持的库,而是使用 BouncyCastle库(或其部分)可能更值得推荐。他们有很多文档,以及 SkipJack 实现,也是。
我不确定为什么您需要使用 Skipjack 而不是 JRE 附带的任何密码 - 只是为了较小的块大小?
如果我理解正确的话,Skip32 是一个单独的密码(适用于 4 字节块),只需按照与 Skipjack(适用于 8 字节块)类似的原理构建即可。我没有找到它的任何规范,只有一些 C 和 Perl 源代码,所以我怀疑是否会有一些可用的 Java 实现。查看 Wikipedia 上的格式保留加密,或给定传统块大小的强块密码,您能否创建一个具有小块大小的强块密码? 在 Cryptography Stack Exchange 上,其中显示了其他从大块密码构建小块密码的方法。
The code you found belongs to the Cryptix project. You need not just this one file, but you should take the whole package. Take the JCE package, install it as a provider. Then you should be able to use
But actually, instead of using an unsupported library like Cryptix, using the BouncyCastle library (or parts thereof) might be more recommendable. They have lots of documentation, and a SkipJack-implementation, too.
I'm not sure why you would need to use Skipjack instead of any cipher which comes with your JRE, though - just for the smaller block size?
If I understand right, Skip32 is a separate cipher (working on 4-byte blocks), just build by similar principles like Skipjack (which works on 8-byte blocks). I didn't find any specification of it, only some C and Perl source code, so I doubt there will be some Java implementation available. Have a look at Format-preserving encryption on Wikipedia, or Can you create a strong blockcipher with small blocksize, given a strong blockcipher of conventional blocksize? on Cryptography Stack Exchange, which show other ways of building a small-block cipher from a larger one.
您可能会找到此博客发布关于使用分组密码进行安全排列的文章,有助于弄清楚如何实现它。任何具有足够短块大小的块密码就足够了。
You might find this blog post on secure permutations with block ciphers useful in figuring out how to implement it. Any block cipher with a sufficiently short block size will suffice.