@Override public void storeKey(Key key) throws KeyStoringException { Path keyPath = FileSystemService.getUserRapidMinerDir().toPath().resolve(DEFAULTKEY_FILE_NAME); try { KeyGeneratorTool.storeKey(key.getEncoded(), keyPath); } catch (IOException e) { throw new KeyStoringException("Could not store new cipher key", e); } }
@Override public SecretKey loadKey() throws KeyLoadingException { // try to load key from file File keyFile = new File(FileSystemService.getUserRapidMinerDir(), DEFAULTKEY_FILE_NAME); try (FileInputStream fis = new FileInputStream(keyFile); ObjectInputStream in = new ObjectInputStream(fis)) { int length = in.readInt(); byte[] rawKey = new byte[length]; int actualLength = in.read(rawKey); if (length != actualLength) { throw new IOException("Cannot read key file (unexpected length)"); } return KeyGeneratorTool.makeKey(rawKey); } catch (IOException e) { // catch to log the problem, then throw again to indicate error LogService.getRoot() .log( Level.WARNING, "com.rapidminer.tools.cipher.KeyGeneratorTool.read_key_error", e.getMessage()); throw new KeyLoadingException("Cannot retrieve key: " + e.getMessage()); } }