Provider getProperty() method in Java with Examples
The getProperty() method of java.security.Provider class is used to search for the property with the specified key in this property list. If the key is not found in this property list, the default property list, and its defaults, recursively, are then checked. The method returns null if the property is not found.
Syntax:
public String getProperty(String key)
Parameters: This method takes the property key as parameter.
Return Value: This method returns the value in this property list with the specified key value or null if the property is not found.
Below are the examples to illustrate the getProperty() method:
Example 1:
// Java program to demonstrate // getProperty() method import java.security.*; import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { // Declaring int values int i = 10; try { // creating the object of KeyPairGenerator KeyPairGenerator sr = KeyPairGenerator.getInstance("DSA", "SUN"); // getting the Provider of the KeyPairGenerator sr // by using method getProvider() Provider provider = sr.getProvider(); // Declaring the variable of set<Map> type Set<Object> set; // getting unmodifiable Set view of the property entries set = provider.keySet(); // Creating the object of iterator to iterate set Iterator iter = set.iterator(); while (i > 0) { // getting the mapped value in element // using getProperty() method String property = provider.getProperty((String)iter.next()); // printing the property of specified key System.out.println("value is : " + property); i--; } } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } } } |
value is : SHA1withDSA value is : SHA1withDSA value is : SHA1withDSA value is : Software value is : sun.security.provider.JavaKeyStore$DualFormatJKS value is : SHA value is : sun.security.provider.SHA value is : sun.security.provider.JavaKeyStore$CaseExactJKS value is : Software value is : sun.security.provider.DSA$SHA256withDSA
Example 2:
// Java program to demonstrate // getProperty() method import java.security.*; import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { // Declaring int values int i = 10; try { // creating the object of KeyPairGenerator KeyPairGenerator sr = KeyPairGenerator.getInstance("DSA", "SUN"); // getting the Provider of the KeyPairGenerator sr // by using method getProvider() Provider provider = sr.getProvider(); // getting the mapped value in element // using getProperty() method System.out.println("Trying to search for unspecified key"); String property = provider.getProperty("geeks"); // printing the property of specified key System.out.println("value is : " + property); } catch (NoSuchAlgorithmException e) { System.out.println("Exception thrown : " + e); } } } |
Trying to search for unspecified key value is : null
Recommended Posts:
- Properties getProperty(key) method in Java with Examples
- Properties getProperty(key, defaultValue) method in Java with Examples
- Provider get() method in Java with Examples
- Provider toString() method in Java with Examples
- Provider getName() method in Java with Examples
- Provider getInfo() method in Java with Examples
- Provider values() method in Java with Examples
- Provider keys() method in Java with Examples
- Provider keySet() method in Java with Examples
- Provider entrySet() method in Java with Examples
- Provider elements() method in Java with Examples
- Provider getVersion() method in Java with Examples
- Provider getService() and getServices() method in Java
- getproperty() and getproperties() methods of System Class in Java
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



