Possible to generate CSR using java.security without sun packages or external library?

送分小仙女□ 提交于 2019-12-25 11:58:11

问题


Is it possible to generate a certificate signing request using Java code without using sun.* or com.sun.* packages, and without using an external library? If I need to use a library like BouncyCastle I will look into it, but all my searching so far only shows examples which use sun packages or BouncyCastle and I'd prefer to stick to the raw API if possible.

And, what's the best approach to doing this if what I'm trying is not possible?


回答1:


I don't think this is possible. Accepting this until someone has a better answer or it becomes possible.

FWIW, I ended up using the shell to call keytool to do this.




回答2:


Sorry for the very late response but figured I'd try anyway. Bouncy Castle or Java libraries make your life a hell of a lot easier for this task. But if you can't use these libraries for your project then my response to you is still "yes" but you will have to become intimately familiar with ASN1 encoding. I see no reason why you cannot take an existing CSR to learn from. This site(http://lapo.it/asn1js/) helped immensely in understanding ASN1 when I had to do similar things. Once you see how the CSR is formatted, with the help of the ASN1 tool I referred to earlier, it becomes clear how to re-purpose the example CSR for your use. At a high level you would

  1. read in the example file
  2. parse by TLV (type-length-value) encoding
  3. replace field with your desired data
  4. digitally sign
  5. embed the signature
  6. write back content to file

The java.security.Signature object should be able to help you with the signing part.



来源:https://stackoverflow.com/questions/13639514/possible-to-generate-csr-using-java-security-without-sun-packages-or-external-li

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!