假设我有一个 IP 地址,192.168.1.1
我希望我的程序基于此 IP 地址创建一个随机的单字字符串,无需 key 或密码或额外的安全措施即可轻松解密。
例如。
I enter 192.168.1.1
Program converts it to AzlQrEHCSD or some other random string
I enter this string in the program
It gets converted back to 192.168.1.1
是否有任何简单的算法可以在不生成 key 或其他密码等内容的情况下执行此操作?我知道 key 和密码是加密和解密的必须,但我的场景不需要。
最佳答案
我知道它有点矫枉过正,但我会使用 jasypt图书馆,因为它真的很容易使用。您只需要随机种子即可加密或解密。
这里是加密数据的源代码:
String seed = "ipNumber";
String myIpValue = "192.168.0.1";
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(seed);
String encrypted= encryptor.encrypt(myIpValue);
对于数据解密:
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(seed);
String decrypted = encryptor.decrypt(encrypted);
或者您可以将您的字符串编码或解码为 base64 示例如下所示: Base64 Java encode and decode a string
关于java - java中的简单加密-无 key /密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29226813/