我有一个项目,使java中的字符串输入加密和解密。我花了一周的时间做一些研究。我真的很感激如果你有示例源代码或算法AES和算法Twofish在java中的函数方法,我可以在我的项目中使用。我真的需要你的帮助。希望有个人能成为我的救世主。非常感谢。
发布于 2014-07-10 16:40:09
对于AES,你可以使用java的库。
休眠代码将给你一个开始的想法。
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class AES {
public void run() {
try {
String text = "Hello World";
String key = "1234567891234567";
// Create key and cipher
Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
// encrypt the text
cipher.init(Cipher.ENCRYPT_MODE, aesKey);
byte[] encrypted = cipher.doFinal(text.getBytes());
System.out.println("Encrypted text: " + new String(encrypted));
// decrypt the text
cipher.init(Cipher.DECRYPT_MODE, aesKey);
String decrypted = new String(cipher.doFinal(encrypted));
System.out.println("Decrypted text: " + decrypted);
}catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
AES app = new AES();
app.run();
}
}https://stackoverflow.com/questions/24668843
复制相似问题