9

In JDK8 the class sun.security.x509.CertAndKeyGen does not exists anymore. Also sun.security.pkcs.PKCS10 is missing. In JDK7 they existed. What could be an alternatives to these classes methods?

Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117
  • Why do you need to use implementation-specific classes instead of JCA API? – Oleg Estekhin May 14 '15 at 16:42
  • I was using those methods in my application - it is like `keytool.jar`, but has convenient user interface. Will back to it later, now busy with other projects. Temporary using JDK7 for that application. – Ernestas Gruodis May 14 '15 at 18:06

3 Answers3

9

I think you are looking for: sun.security.tools.keytool.CertAndKeyGen

You'll find it inside the rt.jar under the JRE libraries.

Keep in mind this class is outside of J2SE, it's likely only available with OpenJDK, so for example the GNU Compiler won't have it.

mikeapr4
  • 2,830
  • 16
  • 24
  • my tests on travis, which i believe is ubuntu, is that CertAndKeyGen is not available on any flavor of java for ubuntu, versions 6-8 openjdk or oracle – spy May 27 '17 at 20:59
  • Adding rt.jar in the classpath solved the IntelliJ compilation issue. – Anil Kamaraju Feb 26 '20 at 12:54
7

If you are using maven, put this in pom.xml. (from this question):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.2</version>
  <configuration>
     <fork>true</fork>
     <compilerArgument>-XDignore.symbol.file</compilerArgument>
  </configuration>
</plugin>
Community
  • 1
  • 1
mesompi
  • 659
  • 6
  • 12
  • Thank you, that works. Though I don't understand why. – Sridhar Sarnobat Aug 03 '17 at 16:59
  • I'm trying to build Openfire using Intellij IDEA. I have latest Java SDK 1.8 installed on my Win 10 machine. Got the same error on import sun.security.x509.GeneralNameInterface;. There are multiple pom.xml files, one global for a project folder, one in xmppserver subfolder. I tried to add the settings you described - it didn't fix error. – vkelman Feb 07 '19 at 16:53
  • Got it. Somehow on my machine there was JDK 11 installed besides JDK 1.8. How it got there I don’t remember… maybe team which initially prepared my laptop did it… I don’t know. Then, in File->Project Structure -> Project Settings -> Project Project SDK was set to 11, not to 1.8. I don’t remember setting it… maybe IntelliJ IDEA chose maximum available when I first opened Openfire project? – vkelman Feb 07 '19 at 19:01
-1

You should switch to the BouncyCastle API instead.

jokernoel
  • 83
  • 4