diff --git a/src/main/java/org/gcube/common/encryption/SymmetricKey.java b/src/main/java/org/gcube/common/encryption/SymmetricKey.java index b40a127..d9607bc 100644 --- a/src/main/java/org/gcube/common/encryption/SymmetricKey.java +++ b/src/main/java/org/gcube/common/encryption/SymmetricKey.java @@ -1,6 +1,8 @@ package org.gcube.common.encryption; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.InvalidKeyException; @@ -45,13 +47,13 @@ public final class SymmetricKey { return keyContextMap.get(ScopeProvider.instance.get()); } - public static Key loadKeyFromFile(String keyFileName, String keyAlgorithm) throws InvalidKeyException { - try(InputStream is = SymmetricKey.class.getResourceAsStream("/" + keyFileName)) { + public static Key loadKeyFromFile(File keyFile, String keyAlgorithm) throws InvalidKeyException { + try(InputStream is = new FileInputStream(keyFile)) { byte[] rawKey = getBytesFromStream(is); Key key = new SecretKeySpec(rawKey, 0, rawKey.length, keyAlgorithm); return key; } catch(Exception e) { - throw new InvalidKeyException("Unable to load the Key " + keyFileName + " from the classpath"); + throw new InvalidKeyException("Unable to load the Key " + keyFile.getAbsolutePath() + " from the classpath"); } }