
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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.