在JAVA中快速简单的字符串加密/解密

我需要一种快速简单的方法来 数据的“很多” 。我尝试了 但在我的

手机上崩溃了。我大约有 (字符串)。

BasicTextEncryptor textEncryptor = new BasicTextEncryptor();

textEncryptor.setPassword("password");

String myEncryptedText = textEncryptor.encrypt(input);

还有其他方法吗?我不需要极高的安全性,它需要 !

回答:

Java-从配置文件加密/解密用户名和密码

链接上方的代码

DESKeySpec keySpec = new DESKeySpec("Your secret Key phrase".getBytes("UTF8"));

SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");

SecretKey key = keyFactory.generateSecret(keySpec);

sun.misc.BASE64Encoder base64encoder = new BASE64Encoder();

sun.misc.BASE64Decoder base64decoder = new BASE64Decoder();

.........

// ENCODE plainTextPassword String

byte[] cleartext = plainTextPassword.getBytes("UTF8");

Cipher cipher = Cipher.getInstance("DES"); // cipher is not thread safe

cipher.init(Cipher.ENCRYPT_MODE, key);

String encryptedPwd = base64encoder.encode(cipher.doFinal(cleartext));

// now you can store it

......

// DECODE encryptedPwd String

byte[] encrypedPwdBytes = base64decoder.decodeBuffer(encryptedPwd);

Cipher cipher = Cipher.getInstance("DES");// cipher is not thread safe

cipher.init(Cipher.DECRYPT_MODE, key);

byte[] plainTextPwdBytes = (cipher.doFinal(encrypedPwdBytes));

以上是 在JAVA中快速简单的字符串加密/解密 的全部内容, 来源链接: utcz.com/qa/434776.html

回到顶部