jalpesh_007 -3 Newbie Poster

I have implemented RSA using java as shown below.

mport java.math.BigInteger;

import java.util.Random;

class SimpleRSA {

public static BigInteger p, q, N, v, k, d;

public static void main(String[] args) {

// p & q are prime numbers

Random myRandom = new Random(0);

p = BigInteger.probablePrime(512, myRandom);

q = BigInteger.probablePrime(512, myRandom);

System.out.println("Value of p:" + p);

System.out.println("Value of q:" + q);

// N = pq

N = p.multiply(q);

System.out.println("Value of N:" + N);

// v = (p-1)*(q-1)

v =

(p.subtract(BigInteger.valueOf(1))).multiply(

q.subtract(BigInteger.valueOf(1)));

System.out.println("Value of v:" + v);

// Compute k such that gcd(k, v) = 1

k = new BigInteger("3");

while(v.gcd(k).intValue() > 1) k = k.add(new BigInteger("2"));

System.out.println("Value of k:" + k);

// Compute d such that (d * k)%v = 1

d = k.modInverse(v);

System.out.println("Value of d:" + d);

System.out.println("Public Key (k,N): (" + k + "," + N + ")");

System.out.println("Private Key (d,N): (" + d + "," + N + ")");

// Encryption

String text = "Welcome to Java";

System.out.println("Sample text:" + text);

byte[] cipherData = text.getBytes();

BigInteger a = new BigInteger(cipherData);

System.out.println("BigInteger a:" + a);

BigInteger b = a.modPow(k, N);

System.out.println("Encrypted data:" + b);

// Decryption

BigInteger c = b.modPow(d, N);

byte[] decryptedData = c.toByteArray();

String plainText = new String(decryptedData);

System.out.println("Decrypted data:" + plainText);

}

}

Now i want to implement it using socket programming.please send me idea how to implement this using Socket programming and how to run this on different machines.

hoping for positive reply....thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.