KeyPair projectRsaKeyPair = RsaUtils.generateRsaKeyPair(RsaUtils.SMALL_KEYSIZE);
project.setPublicKey(projectRsaKeyPair.getPublic());
project.setPrivateKey(projectRsaKeyPair.getPrivate());
} catch (IOException e) {
throw new RepositoryException("Error encrypting secrets", e);
}
int rows = db.createProject(key, secretData, metadata, project.publicKeyData, project.privateKeyData);
if (rows != 1) {
throw new RepositoryException("Unexpected number of rows inserted");
}
ProjectEntity created = findProjectByKey(db, key);
if (created == null) {
throw new RepositoryException("Created project not found");
}
UserProjectEntity userProjectEntity = new UserProjectEntity();
userProjectEntity.userId = owner.id;
userProjectEntity.projectId = created.id;
userProjectEntity.addRole(RoleId.OWNER);
db.insertUserProject(userProjectEntity);
return created;
} catch (SQLException e) {
throw new RepositoryException("Error creating project", e);
} finally {
db.close();
}
}