【问题标题】:while migrating the code from 1.11 to 2.x version , I am unable to find alternate for PEM in AWS java 2.x version在将代码从 1.11 迁移到 2.x 版本时,我无法在 AWS java 2.x 版本中找到 PEM 的替代品
【发布时间】:2019-11-20 07:06:51
【问题描述】:

您能否建议 PEM 读取私钥的替代类。代码如下:

import com.amazonaws.auth.PEM;

public PrivateKey getPrivateKey(String filename1) throws Exception {                
    InputStream res= new FileInputStream(filename1);              
    PrivateKey key = PEM.readPrivateKey(res);              
    return key;         
}

【问题讨论】:

    标签: aws-java-sdk-2.x


    【解决方案1】:

    一般的 Java API 怎么样?

    public PrivateKey read(String filename) throws Exception {
        final byte[] bytes = Files.readAllBytes(Paths.get(filename));
        final PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(bytes);
        final KeyFactory kf = KeyFactory.getInstance("RSA");
    
        return kf.generatePrivate(spec);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 1970-01-01
      • 2018-04-27
      相关资源
      最近更新 更多