How to write a rsa algorithm using thread

Ads
 

How to write a rsa algorithm using thread

Hi... This my **rsa algorithm sequential code..can u anyone plz change/convert to concurrent java or parallel this code..

print("code sample");

import java.security.KeyPairGenerator;

import java.security.KeyPair;

import java.security.PublicKey;

import java.security.PrivateKey;

import javax.crypto.Cipher;

public class rsa {

private static byte[] encrypt(byte[] inpBytes, PublicKey key,

  String xform) throws Exception {

Cipher cipher = Cipher.getInstance(xform);

cipher.init(Cipher.ENCRYPT_MODE, key);

return cipher.doFinal(inpBytes);

}

private static byte[] decrypt(byte[] inpBytes, PrivateKey key,

  String xform) throws Exception{

Cipher cipher = Cipher.getInstance(xform);

cipher.init(Cipher.DECRYPT_MODE, key);

return cipher.doFinal(inpBytes);

}

public static void main(String[] unused) throws Exception {

long starttime =System.currentTimeMillis();

String xform = "RSA/NONE/PKCS1PADDING";

// Generate a key-pair

KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");

kpg.initialize(1024); // 1024 is the keysize.

KeyPair kp = kpg.generateKeyPair();

PublicKey pubk = kp.getPublic();

PrivateKey prvk = kp.getPrivate();



byte[] dataBytes =

    "J2EE Security for Servlets, EJBs and Web Services".getBytes();



byte[] encBytes = encrypt(dataBytes, pubk, xform);
System.out.println(encBytes);

byte[] decBytes = decrypt(encBytes, prvk, xform);
System.out.println(decBytes);

String res=new String(decBytes);

boolean expected = java.util.Arrays.equals(dataBytes, decBytes);

System.out.println("Test " + (expected ? "SUCCEEDED!" : "FAILED!"));
System.out.println(res);
long endtime=System.currentTimeMillis();

System.out.println("Time required for sequential rsa algorithm:"+(endtime-starttime)+"millisecond");

}

}

THANKS

LAVANYA

View Answers

Ads









Related Tutorials/Questions & Answers:
How to write a rsa algorithm using thread
How to write a rsa algorithm using thread   Hi... This my **rsa algorithm sequential code..can u anyone plz change/convert to concurrent...("Time required for sequential rsa algorithm:"+(endtime-starttime)+"millisecond
Write an applet to display scrolling image in an applet window using thread.
Write an applet to display scrolling image in an applet window using thread.  Write an applet to display scrolling image in an applet window using thread
Advertisements
How to write to file using FileOutputStream
How to write to file using FileOutputStream  Hi friends, Please help me in java program. How to write to file using FileOutputStream? thanks,   Hi, To write a file using FileOutputStream, we have to use
How to Explain different way of using thread?
How to Explain different way of using thread?  Hi, How to explain how to using different thread in Java program
How to write to file using FileWriter
How to write to file using FileWriter  hi, How to write to file using FileWriter thanks,   Hi, To writing in a file in Java program we... of the FileWriter class can be created using the following of its constructor i.e. FileWriter
How to Explain different way of using thread?
How to Explain different way of using thread?  Hi, How to explain how to using different thread in Java program........   Hi, There are different types Thread in Java program. Here is the explain how to using thread
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
how to write a program to search a record using mvc2
how to write a program to search a record using mvc2   how can we write a code to search a record in table by using java bean as model, servlet as contoller and jsp as view
How to write a search functionality using javascript/jquery
How to write a search functionality using javascript/jquery   How to write a search functionality using javascript/jquery for ex: im searching "s" names it wil display "s" names
how to write a jsp form using html
how to write a jsp form using html  hi, i have written the code as below... but it is showing error. please help me how to resolve it. .html file <html> <head><title>StudentForm</title></head>
how to use Excel Templet to write excel file using java.
how to use Excel Templet to write excel file using java.  how to use Excel Templet to write excel file using java
how to use Excel Template to write excel file using java
how to use Excel Template to write excel file using java  How to use Excel template to write data in that file using java
how to write greater than symbol in a file using java
how to write greater than symbol in a file using java  Hello I want to write < and > symbol in a file but its coming like > and < Please help me   Hi Friend, You can write the symbols by taking them
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
creating trafficsignal using thread
creating trafficsignal using thread  please give me code how to create trafic signal using thread and give me it to my email [email protected] thanks
write a programm using java
write a programm using java  print the following using java programming
Spring application in RSA 7.0.0.3
Spring application in RSA 7.0.0.3  how to build a sample spring application using RSA 7.0.0.3
how to write the coding for converting the database data for example population into any type of graph using jsp and servlets?//
coding for converting the database data  how to write the coding for converting the database data for example population into any type of graph using jsp and servlets pls help me out how to write the coding for converting
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
How to Differenciate Main Thread and Child Thread in Java
How to Differenciate Main Thread and Child Thread in Java  hi... Main Thread and Java Child Thread. Please Suggest any example or online link for references. Thanks,   Hi, There are two types of Thread used
implementing an algorithm using multi threads - Java Beginners
implementing an algorithm using multi threads  Hi i need to implement... data from one thread to another thread. I am posting my algorithm which needs...; double d=-6; double F=0.0; double lamsq=0.25; Thread t1 = new Thread
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... bufferedWriter object to write in the file. For more details and examples related to How... and custructor. To open some file we require it to be open in append mode by using
Write a program to print using for loop
Write a program to print using for loop  Write a program to print using for loop * * * *  
How to write image in Jmagick
How to write image in Jmagick  hi, I am new in Java I am using the Jmagick library, how can I write an image in Jmagick ? Thanks.   hi, You can try this snippet into your code ImageInfo ii = new ImageInfo("abc.jpg
how to write this program
how to write this program  Write a program in java which calculates... or numerical grade. You will be submitting TWO versions of this program. Write one version using the scanner object input method and one using the input box input method
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
How to write text on image
How to write text on image  hi, I am using the Jmagick library. I want to write text on image, how is it possible ? Thanks.   hi, I am new in Jmagick but, I used the following code and it might also help you
how to write to file at the end of the line
how to write to file at the end of the line  Hi, Where do i learn how to write to file at the end of the line using Java program. Plz suggest... will help you for "How to write the file at the end of line using Java language
how to write code for this output?
how to write code for this output?   1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
How to write a file in Java?
How to write a file in Java? To write a file in Java use the class FileWriter and BufferedWriter. Class FileWriter: The FileWriter class is used to write... and strings. Example of how to write text to a file in java: import java.io.

Ads