Found 9150 Articles for Object Oriented Programming

KeyPairGenerator genKeyPair() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

146 Views

A key pair can be generated using the genKeyPair() method in the class java.security.KeyPairGenerator. This method requires no parameters and it returns the key pair that is generated.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) throws Exception {       try {          KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA");          KeyPair keyPair = kpGenerator.genKeyPair();          System.out.println(keyPair);       } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); ... Read More

SecureRandom nextBytes() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

429 Views

The number of random bytes as specified by the user can be obtained using the nextBytes() method in the class java.security.SecureRandom. This method requires a single parameter i.e. a random byte array and it returns the random bytes as specified by the user.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String s = "Apple";          byte[] arrB = s.getBytes();         ... Read More

SecureRandom getSeed() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

135 Views

The seed bytes as required can be obtained using the method getSeed() in the class java.security.SecureRandom. This method requires a single parameter i.e. the number of seed bytes that need to be generated and it returns the seed bytes as required.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          byte[] arrB = sRandom.getSeed(5);          System.out.println("The Seed Bytes in array are: " + Arrays.toString(arrB));   ... Read More

SecureRandom setSeed() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

458 Views

The random object can be reseeded using the setSeed() method in the class java.security.SecureRandom. This method requires a single parameter i.e. the required seed byte array and it returns the reseeded random object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String str = "Apple";          byte[] arrB = str.getBytes();          sRandom.setSeed(arrB);          byte[] arrSeed = sRandom.getSeed(5);   ... Read More

SecureRandom getProvider() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

110 Views

The provider for the SecureRandom object can be obtained using the method getProvider() in the class java.security.SecureRandom. This method requires no parameters and it returns the provider for the SecureRandom object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          Provider provider = sRandom.getProvider();          System.out.println("The Provider is: " + provider.getName());       } catch (NoSuchAlgorithmException e) { ... Read More

SecureRandom getAlgorithm() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

158 Views

The name of the algorithm for the SecureRandom object can be obtained using the method getAlgorithm() in the class java.security.SecureRandom. This method requires no parameters and it returns the name of the algorithm for the SecureRandom object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String algorithmName = sRandom.getAlgorithm();          System.out.println("The Algorithm is: " + algorithmName);       } catch (NoSuchAlgorithmException e) { ... Read More

SecureRandom generateSeed() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

190 Views

The number of seed bytes can be obtained using the method generateSeed() in class java.security.SecureRandom. This method requires a single parameter i.e. the number of seed bytes and it returns the seed bytes that are generated.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          byte[] arrB = sRandom.generateSeed(5);          System.out.println("The seed bytes generated are: " + Arrays.toString(arrB));       } catch (NoSuchAlgorithmException e) ... Read More

SecureRandom getInstance() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

354 Views

A SecureRandom object can be obtained using the getInstance() method in class java.security.SecureRandom. This SecureRandom object is useful in implementing the Random Number Generator (RNG) algorithm that is specified.The getInstance() method requires a single parameter i.e. the Random Number Generator (RNG) algorithm and it returns the SecureRandom object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String s = "Apple";          byte[] arrB = ... Read More

Java Signature getInstance() method

Alshifa Hasnain
Updated on 11-Dec-2024 19:33:16

2K+ Views

In this article, we will learn about the Signature.getInstance() method, how it works, and examples that demonstrate its usage. A signature object that can implement the required signature algorithm can be obtained using the method getInstance(). The Signature.getInstance() method in Java is a crucial component of the Java Cryptography Architecture (JCA). It is part of the java.security package and is used to create and manage digital signatures. Java Cryptography Architecture (JCA)  The Java Cryptography Architecture (JCA) is a collection of APIs designed to implement modern cryptographic concepts like digital signatures, message digests, and certificates. It provides developers with tools to ... Read More

Java Signature toString() method

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

393 Views

The string representation for the signature object can be obtained using the method getString() in the class java.security.Signature. This includes information such as the object state, algorithm name etc. The method getString() requires no parameters and it returns the provider for the signature object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo { public static void main(String[] argv) { try { Signature signature = Signature.getInstance("SHA256withRSA"); ... Read More

Advertisements