如何获取privateKey作为org.springframework.core.io.Resource

时间:2019-03-22 21:23:44

标签: spring-integration

我正在使用Spring集成通过私钥连接到SFTP Server。 私钥作为外部字符串进入应用程序。如何在以下代码中使用密钥:

 <bean id="test"
        class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${host}" />
        <property name="privateKey" value="" />
        <property name="port" value="${port}" />
        <property name="user" value="${username}" />
        <property name="allowUnknownKeys" value="true" />
    </bean>

1 个答案:

答案 0 :(得分:1)

如果您的意思是密钥的编码方式类似于某个字符串,那么您需要考虑将其包装到 public static int bestMoves(char[][] coordinates, int movesPossible, int playerX, int playerY, int mapSize, boolean[][] visited){ char[][] mapCopy = new char[mapSize][mapSize]; boolean[][] visitedCopy = new boolean[mapSize][mapSize]; for (int i = 0; i < mapSize; i++){ for (int j = 0; j < mapSize; j++){ mapCopy[i][j] = coordinates[i][j]; } } for (int i = 0; i < mapSize; i++){ for (int j = 0; j < mapSize; j++){ visitedCopy[i][j] = visited[i][j]; } } if (movesPossible > 0){ if (playerX - 1 >=0 && !visited[playerY][playerX-1]){ visitedCopy[playerX-1][playerY] = true; if (coordinates[playerY][playerX-1] == '1'){ return 1 + bestMoves(mapCopy, movesPossible-1, playerX-1, playerY, mapSize-1,visited); }else{ return bestMoves(mapCopy, movesPossible-1, playerX-1, playerY, mapSize-1,visited); } } if (playerY - 1 >=0 && !visited[playerY-1][playerX]){ visitedCopy[playerY-1][playerX] = true; if (coordinates[playerY-1][playerX] == '1'){ return 1 + bestMoves(mapCopy, movesPossible-1, playerX, playerY-1, mapSize-1,visited); }else{ return bestMoves(mapCopy, movesPossible-1, playerX, playerY-1, mapSize-1,visited); } } else if (playerY + 1 >= mapSize && !visited[playerY-1][playerX]){ visitedCopy[playerY][playerX] = true; if (coordinates[playerY+1][playerX] == '1'){ return 1 + bestMoves(mapCopy, movesPossible-1, playerX, playerY+1, mapSize-1,visited); }else{ return bestMoves(mapCopy, movesPossible-1, playerX, playerY+1, mapSize-1,visited); } } else if (playerX + 1 >= mapSize && !visited[playerY-1][playerX]){ visitedCopy[playerY][playerX] = true; if (coordinates[playerY+1][playerX] == '1'){ return 1 + bestMoves(mapCopy, movesPossible-1, playerX+1, playerY, mapSize-1,visited); }else{ return bestMoves(mapCopy, movesPossible-1, playerX+1, playerY, mapSize-1,visited); } }else{ return 0; } }else{ return 0; } 中。

我们假设您将其作为某个文件中的属性,并且使用属性占位符:

ByteArrayResource