繁体   English   中英

从 Azure Key Vault 检索证书(JKS 或 PFX)

[英]Retrieve the certificate (JKS or PFX) from Azure Key Vault

我想使用 Java 创建 jwt 令牌。 如果我将证书(JKS)本地存储在我的机器中,我的代码就可以工作。 但我想使用 Azure Key Vault 中的证书而不将其存储在本地。 如何修改文件部分? 如果它是 PFX 而不是 JKS 怎么办?

 KeyStore keystore = KeyStore.getInstance("JKS");

              File keystoreFile = ResourceUtils.getFile("classpath:"+Keystore);
              keystore.load(new FileInputStream(keystoreFile), KeyPassword.toCharArray());
                      
              PrivateKey privateKey = (PrivateKey) keystore.getKey(KeyAlias, KeyPassword.toCharArray());

As per KeyStore JavaDoc ( https://docs.oracle.com/javase/7/docs/api/java/security/KeyStore.html#load(java.io.InputStream,%20char[]) ), the method signature you正在使用的是KeyStore.load(InputStream, char[]) 这意味着InputStream不必是FileInputStream 从 Azure 下载您的密钥库字节,将它们包装到 ByteArrayInputStream 中并执行您需要执行的任何操作。

至于如何读取pfx密钥库,您应该能够通过启动KeyStore.getInstance("pkcs12", "SunJSSE")之类的密钥库,然后像加载 JKS 密钥库一样加载它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM