Fixed code to generate DB Key

This commit is contained in:
Luca Frosini 2020-05-08 12:41:58 +02:00
parent 35e9883a38
commit c93cd35172
1 changed files with 13 additions and 4 deletions

View File

@ -1,5 +1,14 @@
package org.gcube.informationsystem.resourceregistry.dbinitialization;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.security.Key;
import java.util.Properties;
import org.gcube.common.encryption.KeyFactory;
import org.gcube.common.encryption.KeySerialization;
import org.gcube.common.encryption.SymmetricKey;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
@ -35,7 +44,7 @@ public class DatabaseEnvironmentTest {
@Test
public void generateDBKey() throws Exception {
Properties properties = new Properties();
InputStream input = DatabaseEnvironmentTest.class.getClassLoader().getResourceAsStream("config.properties");
InputStream input = DatabaseEnvironmentTest.class.getClassLoader().getResourceAsStream("config.properties.prod");
// load a properties file
properties.load(input);
@ -44,10 +53,11 @@ public class DatabaseEnvironmentTest {
String keyAlgorithm = properties.getProperty("DB_KEY_ALGORITHM_VARNAME");
URL url = SymmetricKey.class.getResource(keyFileName);
File keyFile = new File("src/test/resources", keyFileName);
Key key = null;
if(url!=null) {
try {
key = SymmetricKey.loadKeyFromFile(keyFileName, keyAlgorithm);
key = SymmetricKey.loadKeyFromFile(keyFile, keyAlgorithm);
} catch(Exception e) {
}
@ -55,8 +65,7 @@ public class DatabaseEnvironmentTest {
if(key==null){
key = KeyFactory.newAESKey();
File file = new File("src/test/resources", keyFileName);
KeySerialization.store(key, file);
KeySerialization.store(key, keyFile);
}
}
*/