Java简单加密
我想加密存储在磁盘上的文本(配置)文件。 尝试使用 DES 加密我在客户端计算机上遇到了致命错误,后来我发现了该算法无法处理重音字符 (!) 我怀疑这是因为我使用的是旧软件包(sun.misc.BASE64Decoder
) - 但我不确定这就是原因。
但是,我正在寻找一个更简单的解决方案 - 我需要一个非常简单的加密(我知道有些人不会同意这一点) - 不是 RSA 大约 128 位密钥,只是遮挡了好奇的眼睛中的文本。
很奇怪我在网上找不到一个简单的解决方案。
如何实现一个简单的加密方案?
I would like to encrypt a textual (configuration) file stored on disk.
Trying to use DES encryption I've had fatal error on client machines, I later found out the algorithm could not handle accented characters (!)
I suspect that was because I was using old packages (sun.misc.BASE64Decoder
) - but I'm not sure that is the reason.
However, I'm looking for a simpler solution - I need a really simple encryption (I know some people would not agree on that) - not RSA of 128 bit keys or so, just obscuring the text from curious eyes.
It is really weird that I could not find a simple trivial solution on the web.
How can I implement a simple encryption scheme?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
查看Java 简化加密 (Jasypt)。
Check out the Java Simplified Encryption (Jasypt).
我正在使用这个简单的 One-Time-Pad 算法:
不要忘记添加
commons-codec
到类路径。I'm using this simple One-Time-Pad algorithm:
Don't forget to add
commons-codec
to classpath.加密算法适用于原始字节,而不是字符。
您无法处理重音字符的原因是您用来将字符与原始字节相互转换的代码无法处理 Unicode。
您应该使用 AES;有关如何在 Java 中使用它的示例,请参阅此处。
编辑:现在,您可能只是将其隐藏起来以防止好奇的目光,但无法预测未来会发生什么,而且现在使用强加密总是得多更好却迟迟没有发现你应该这样做却没有。
Encryption algorithms work on raw bytes, not characters.
The reason you couldn't handle accented characters was because the code you were using to convert the characters to and from raw bytes didn't handle Unicode.
You should use AES; for an example of how to use it in Java, see here.
EDIT: Right now, you might just be hiding it from curious eyes, but there's no telling what the future will hold, and it is always much better to use strong encryption now and not find out, to late, that you should have but didn't.
ROT13 怎么样?它可能是有史以来最简单和最糟糕的加密(也称为凯撒密码)
下面是 Jay Kominek 在 Java 中的基本实现:
How about ROT13? It's probably the most simple and worst encryption ever (it was also called the Caeser's Cipher)
Here's a basic implementation in Java by Jay Kominek:
如果您不想真正加密文本,为什么不使用 Base64 进行编码呢?它看起来像是无稽之谈,但很容易破译。另外,您已经在使用 Base64 代码...
If you're not looking to really encrypt the text, why not encode with Base64? It'll look like nonsense, and it's very easy to decode. Plus, you're already using Base64 code...
如果您要加密一段文本,那么一次性密码本怎么样?一次性本本非常容易创建;您所需要的只是一个随机字节序列,其长度与您要加密的数据相同
If you have a single piece of text to encrypt, what about a one-time-pad? A one-time-pad is very easy to create; all you need is a random sequence of bytes the same length as the data you are encrypting
请参阅如何在 Java 中使用 3des 加密/解密?
BASE64Encoder
用于表示加密的字节数组,而不是实际的输入。See How do I use 3des encryption/decryption in Java?
BASE64Encoder
is used to represent the ciphered array of bytes, not the actual input.