Provider getProperty() method in Java with Examples
Last Updated :
04 Dec, 2018
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:
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
int i = 10 ;
try {
KeyPairGenerator sr = KeyPairGenerator.getInstance( "DSA" , "SUN" );
Provider provider = sr.getProvider();
Set<Object> set;
set = provider.keySet();
Iterator iter = set.iterator();
while (i > 0 ) {
String property = provider.getProperty((String)iter.next());
System.out.println( "value is : " + property);
i--;
}
}
catch (NoSuchAlgorithmException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Output:
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:
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
int i = 10 ;
try {
KeyPairGenerator sr = KeyPairGenerator.getInstance( "DSA" , "SUN" );
Provider provider = sr.getProvider();
System.out.println( "Trying to search for unspecified key" );
String property = provider.getProperty( "geeks" );
System.out.println( "value is : " + property);
}
catch (NoSuchAlgorithmException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Output:
Trying to search for unspecified key
value is : null
Share your thoughts in the comments
Please Login to comment...