Getting a PrivateKey object from a .p12 file in Java

前端 未结 4 1644
[愿得一人]
[愿得一人] 2020-12-05 06:59

As the title suggests, I have .p12 file required for google service account api access. In order to get the credential to connect to the api, there\'s a field .setServiceAcc

4条回答
  •  我在风中等你
    2020-12-05 07:42

    I think it's easier to call Google's SecurityUtils directly, e.g.:

    PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), this.getClass().getResourceAsStream("keyFile.p12"), "notasecret", "privatekey", "notasecret")
    

    It's one-line and you don't have to worry about aliasing.

提交回复
热议问题