Provider get() method in Java


The value to which a key is mapped can be obtained using the get() method in the class java.security.Provider. This method requires a single parameter i.e. the key whose value is required. It returns the value to which the key is mapped or it returns null if there is no value to which the key is mapped.

A program that demonstrates this is given as follows −

Example

 Live Demo

import java.security.*;
import java.util.*;
public class Demo {
   public static void main(String[] argv) {
      try {
         SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");
         Provider p = sRandom.getProvider();
         Set<Object> set = p.keySet();
         Iterator i = set.iterator();
         int x = 30;
         while (x > 0) {
            Object val = p.get(i.next());
            System.out.println(val);
            x--;
         }
      } catch (NoSuchAlgorithmException e) {
         System.out.println("Error!!! NoSuchAlgorithmException");
      }
   }
}

The output of the above program is as follows −

Output

SHA1withDSA
SHA1withDSA
SHA1withDSA
Software
sun.security.provider.JavaKeyStore$DualFormatJKS
SHA
sun.security.provider.SHA
sun.security.provider.JavaKeyStore$CaseExactJKS
Software
sun.security.provider.DSA$SHA256withDSA
SHA
SHA1withDSA
Software
Software
Software
sun.security.provider.DSA$RawDSA
X.509
java.security.interfaces.DSAPublicKey|java.security.interfaces.DSAPrivateKey
sun.security.provider.certpath.IndexedCollectionCertStore
sun.security.provider.Sun
SHA
SHA1withDSA
sun.security.provider.DomainKeyStore$DKS
Software
SHA256withDSA
SHA224withDSA
1024
1024
Software
sun.security.provider.DSAKeyFactory

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

248 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements