最近我遇到了一个要求,用于使用symmetric key algorithm
来加密数据库密码,该密码用于为独立调度程序创建连接。AIX jre没有抛出任何异常
第一个数据库密码使用java swing utility
进行加密,其中我使用aes128
位加密并将其放入属性文件中。 然后在创建连接的connection manager
类中,从属性文件中读取密码并使用相同的密钥进行解密。在我的最后,我已经在aix服务器上测试了这个代码在工作,但是在客户端它不工作。它无法解密。在连接管理器类中执行以下语句后,它将从方法中退出而无任何异常。
pwd=AES128Encryption.decrypt(PAYTFHomeProperties.getProperty("PWD").toString().trim());
我假设这与jce.jar
有关。这里是我解密和连接管理器类的解密密码的方法。
protected Connection getConnection(){
try{
mcName=PAYTFHomeProperties.getProperty("MACHINE_NAME");
sid=PAYTFHomeProperties.getProperty("SID");
port=PAYTFHomeProperties.getProperty("DB_PORT");
UserName=PAYTFHomeProperties.getProperty("USER_NAME");
pwd=AES128Encryption.decrypt(PAYTFHomeProperties.getProperty("PWD").toString().trim());
debug("getEncrptdData||encrypted pwd::"+PAYTFHomeProperties.getProperty("PWD"));
System.out.println("decrypted pwd::"+pwd);
tns=PAYTFHomeProperties.getProperty("TNS");
hostString="jdbc:oracle:thin:@"+mcName+":"+port+":"+sid;
OracleConnectionPoolDataSourcecpds=new OracleConnectionPoolDataSource();
cpds.setDriverType("thin");
cpds.setNetworkProtocol("tcp");
cpds.setServerName(mcName);
cpds.setDatabaseName(sid);
cpds.setPortNumber(Integer.parseInt(port));
cpds.setUser(UserName);
cpds.setPassword(pwd);
pc = (oracle.jdbc.pool.OraclePooledConnection)cpds.getPooledConnection();
connection con= (Connection)pc.getConnection();
} catch(Exception e){
System.out.println("getConnection"+e.toString());
}
return con;
}
这里是我AES128Encryption
类的解密方法
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.*;
public class AES128Encryption {
private static final String ALGO = "AES/ECB/PKCS5Padding";
public static String decrypt(String encryptedData) throws Exception {
Cipher c = Cipher.getInstance(ALGO);
byte[] raw = "************".getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
c.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}
}
异常跟踪? –
@JunedAhsan根本没有。 –