Problem Statement (Java Security):
Print or list all Java Cryptography Extension (JCE)/Java Cryptography Architecture (JCA) providers configured in Java Runtime.
How to check providers enabled in Java Runtime?
- Navigate to “<Java Installation>/jre/lib/security/” (Linux) and “<Java Installation>\jre\lib\security\” (Windows).
- Open java.security file and we can have a look at registered providers.
- We can find registered providers as follows and it may vary depending upon Java version:
# # List of providers and their preference orders: # security.provider.1=sun.security.provider.Sun security.provider.2=sun.security.rsa.SunRsaSign security.provider.3=sun.security.ec.SunEC security.provider.4=com.sun.net.ssl.internal.ssl.Provider security.provider.5=com.sun.crypto.provider.SunJCE security.provider.6=sun.security.jgss.SunProvider security.provider.7=com.sun.security.sasl.Provider security.provider.8=org.jcp.xml.dsig.internal.dom.XMLDSigRI security.provider.9=sun.security.smartcardio.SunPCSC security.provider.10=sun.security.mscapi.SunMSCAPI security.provider.11=org.bouncycastle.jce.provider.BouncyCastleProvider
Program – list of security providers in Java Runtime:
- JDK “java.security.Security” class to get list of register providers.
Method Name | Description |
---|---|
Provider[] getProviders() | Returns an array containing all the installed providers. |
- There are 11 providers configured in our java runtime (as shown above).
- We will observe the output of below program, wherein we will get list of 11 providers and their corresponding version.
package org.learn; import java.security.Provider; import java.security.Security; import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; public class ListProviders { public static void main(String[] args) { Provider[] providers = Security.getProviders(); AtomicInteger atomicInteger = new AtomicInteger(1); Arrays.stream(providers) .map(provider -> String.format("%d. Name: %s and Version: %s", atomicInteger.getAndIncrement(), provider.getName(), provider.getVersion())) .forEach(System.out::println); } }
Output: List of JCA/JCE providers in Java Runtime
1. Name: SUN and Version: 1.8 2. Name: SunRsaSign and Version: 1.8 3. Name: SunEC and Version: 1.8 4. Name: SunJSSE and Version: 1.8 5. Name: SunJCE and Version: 1.8 6. Name: SunJGSS and Version: 1.8 7. Name: SunSASL and Version: 1.8 8. Name: XMLDSig and Version: 1.8 9. Name: SunPCSC and Version: 1.8 10. Name: SunMSCAPI and Version: 1.8 11. Name: BC and Version: 1.65