- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
KeyPairGenerator getInstance() method in Java
A KeyPairGenerator object with the key pairs for a particular algorithm can be obtained using the getInstance() method in the class java.security.KeyPairGenerator. This method requires a single parameter i.e. the algorithm name and it returns the KeyPairGenerator object created.
A program that demonstrates this is given as follows −
Example
import java.security.*; import java.util.*; public class Demo { public static void main(String[] argv) { try { KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA"); String algorithm = kpGenerator.getAlgorithm(); System.out.println("The Algorithm is: " + algorithm); } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); } catch (ProviderException e) { System.out.println("Error!!! ProviderException"); } } }
Output
The Algorithm is: RSA
Now let us understand the above program.
A KeyPairGenerator object kpGenerator can be obtained using the getInstance() method. Then the algorithm is obtained using the getAlgorithm() method and it is displayed. A code snippet that demonstrates is given as follows −
try { KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSsA"); String algorithm = kpGenerator.getAlgorithm(); System.out.println("The Algorithm is: " + algorithm); }
- Related Articles
- SecureRandom getInstance() method in Java
- Java Signature getInstance() method
- KeyPairGenerator genKeyPair() method in Java
- KeyPairGenerator generateKeyPair() method in Java
- KeyPairGenerator getProvider() method in Java
- KeyPairGenerator getAlgorithm() method in Java
- Java Signature getInstance() method with Examples
- Collections.replaceAll() method and List.replaceAll() method in Java
- Method overloading in Java
- Method overriding in Java
- BigInteger.isProbablePrime() method in Java
- Integer.lowestOneBit() method in Java
- Integer.numberOfLeadingZeros() method in Java
- Integer.numberOfTrailingZeros() method in Java
- Integer.rotateLeft() method in Java

Advertisements