79 lines
2.0 KiB
Java
79 lines
2.0 KiB
Java
package it.valueteam.securityutility;
|
|
|
|
import java.io.*;
|
|
import java.util.Properties;
|
|
import java.security.*;
|
|
|
|
/**
|
|
* <p>Title: </p>
|
|
* <p>Description: Classe per il caricamento nella shared memory della
|
|
* chiave simmetrica dle sistema</p>
|
|
* <p>Copyright: Copyright (c) 2006</p>
|
|
* <p>Company: </p>
|
|
* @author Paolo Marini
|
|
* @version 1.0
|
|
*/
|
|
|
|
public class KeyManager {
|
|
|
|
public KeyManager() {
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
FileInputStream in = null;
|
|
Properties config = null;
|
|
int indirizzo;
|
|
KeyStore store = null;
|
|
Key encryptionKey = null;
|
|
String passphrase = null;
|
|
|
|
String confFile = System.getProperty("security_conf_file");
|
|
|
|
try {
|
|
System.out.println("Inizio caricamento chiave.");
|
|
in = new FileInputStream(confFile);
|
|
config = new Properties();
|
|
config.load(in);
|
|
in.close();
|
|
|
|
passphrase = "";
|
|
Process proc = Runtime.getRuntime().exec("pswd.so");
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.
|
|
getInputStream()));
|
|
passphrase = reader.readLine();
|
|
|
|
if (passphrase==null || passphrase.length()== 0) {
|
|
System.out.println("Specificare la passphrase");
|
|
System.exit(1);
|
|
}
|
|
|
|
|
|
in = new FileInputStream(config.getProperty(CryptoUtility.FILE_KEY));
|
|
store = KeyStore.getInstance("JCEKS");
|
|
store.load(in,passphrase.toCharArray());
|
|
encryptionKey = store.getKey("alias",passphrase.toCharArray());
|
|
|
|
indirizzo = "true".equalsIgnoreCase(config.getProperty(CryptoUtility.INDIRIZZO_DINAMICO))?
|
|
Integer.parseInt(config.getProperty(CryptoUtility.MEMORY_ADDRESS)):
|
|
CryptoUtility.INDIRIZZO_STATICO;
|
|
|
|
KeyJNIBridge bridge = new KeyJNIBridge();
|
|
bridge.writeKey(indirizzo,encryptionKey.getEncoded());
|
|
System.out.println("Caricamento chiave terminato con successo.");
|
|
}
|
|
catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
finally {
|
|
if(in!=null) {
|
|
try {
|
|
in.close();
|
|
}
|
|
catch (IOException ex1) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|