1

我需要使用 REST API 监控 Oracle Cloud Compute VM。我在 Oracle 文档中找到了以下用于使用标头签名的代码行。

String privateKeyFilename = "/.oci/oci_api_key.pem";
PrivateKey privateKey = loadPrivateKey(privateKeyFilename);      
RequestSigner signer = new RequestSigner(apiKey, privateKey);

loadPrivateKey(privateKeyFilename) 方法

private static PrivateKey loadPrivateKey(String privateKeyFilename) {
    System.out.println(SystemUtils.getUserHome().toString() + Paths.get(privateKeyFilename));
    try (InputStream privateKeyStream = Files
            .newInputStream(Paths.get(SystemUtils.getUserHome().toString() + privateKeyFilename))) {
        return PEM.readPrivateKey(privateKeyStream);
    } catch (InvalidKeySpecException e) {
        throw new RuntimeException("Invalid format for private key");
    } catch (IOException e) {
        throw new RuntimeException("Failed to load private key");
    }
}

这些行将涵盖使用密码读取文件。有什么输入吗?

4

0 回答 0