我是JAVA的新手.我打算为我的项目构建一个安全系统.但是,我遇到了一个问题.Eclipse总是指出"java.security.InvalidKeyException:错误的算法:AES或Rijndael需要".我要将加密密钥保存在数据库中.我检查过钥匙是否正确.唯一的问题是我无法解密密文.谁能告诉我这是什么问题?实际上,我已经搜索了一些解决方案,但问题仍未解决.请帮我.非常感谢!
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class AES {
public static void main(String[] args) throws Exception {
String test = "HIHI";
String tmp = null;
SecretKey tempKey1 = generateKey();
saveKey(tempKey1);
SecretKey tempKey2 = loadKey();
tmp = encrypt(test, tempKey1);
String printString = decrypt(tmp, tempKey2);
System.out.println(printString);
}
public static SecretKey generateKey() throws NoSuchAlgorithmException {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(128);
SecretKey …Run Code Online (Sandbox Code Playgroud)