source code for rsa encryption and decryption in java
#1

audio file encryption and decryption using rsa
Reply
#2
import java.math.BigInteger;
import java.util.Random;
import java.io.*;

public class RSA {

private BigInteger p;
private BigInteger q;
private BigInteger N;
private BigInteger phi;
private BigInteger e;
private BigInteger d;
private int bitlength = 1024;
private int blocksize = 256; //blocksize in byte

private Random r;
public RSA() {
r = new Random();
p = BigInteger.probablePrime(bitlength, r);
q = BigInteger.probablePrime(bitlength, r);
N = p.multiply(q);

phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
e = BigInteger.probablePrime(bitlength/2, r);

while (phi.gcd(e).compareTo(BigInteger.ONE) > 0 && e.compareTo(phi) < 0 ) {
e.add(BigInteger.ONE);
}
d = e.modInverse(phi);
}

public RSA(BigInteger e, BigInteger d, BigInteger N) {
this.e = e;
this.d = d;
this.N = N;
}

public static void main (String[] args) throws IOException
{
RSA rsa = new RSA();
DataInputStream in=new DataInputStream(System.in);
String teststring ;
System.out.println("Enter the plain text:");
teststring=in.readLine();
System.out.println("Encrypting String: " + teststring);
System.out.println("String in Bytes: " + bytesToString(teststring.getBytes()));

// encrypt
byte[] encrypted = rsa.encrypt(teststring.getBytes());
System.out.println("Encrypted String in Bytes: " + bytesToString(encrypted));

// decrypt
byte[] decrypted = rsa.decrypt(encrypted);
System.out.println("Decrypted String in Bytes: " + bytesToString(decrypted));

System.out.println("Decrypted String: " + new String(decrypted));

}

private static String bytesToString(byte[] encrypted) {
String test = "";
for (byte b : encrypted) {
test += Byte.toString(b);
}
return test;
}

//Encrypt message
public byte[] encrypt(byte[] message) {
return (new BigInteger(message)).modPow(e, N).toByteArray();
}

// Decrypt message
public byte[] decrypt(byte[] message) {
return (new BigInteger(message)).modPow(d, N).toByteArray();
}
}
Reply
#3
I want a source code to encrypt and decrypt a text file using rsa algorithm.it should do it using the random funtion.
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: file encryption decryption using rsa algorithm javarls seminary in italyg rsa algorithm java, source code in computer graphics to demonstrate encryption using rsa, encryption decryption in java ppt, broadcast encryption java source code, rsa encryption decryption m matlab, rsa encryption decryption matlab, rsa encryption and decyption code in matlab,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  simple java rmi chat application source code 2 19,877 20-07-2018, 12:08 PM
Last Post: Guest
  authentication schemes for session passwords using color and images project source code 2 2,268 03-02-2018, 09:35 AM
Last Post: Nischithnash
  free download source code for online movie ticket booking in java 2 19,317 15-08-2017, 03:21 PM
Last Post: Morshed
  image encryption and decryption using rsa algorithm in matlab 2 8,134 29-05-2017, 04:17 PM
Last Post: Priyanka Bidikar
  download liver tumor ct scan image in matlab with source code 4 8,283 21-05-2017, 09:54 PM
Last Post: abdulrahmanmashaal
  online cab booking source code in asp net 3 8,169 11-05-2017, 10:39 AM
Last Post: jaseela123d
Thumbs Up online catering management system on php with report and source code and ppt 4 9,056 29-04-2017, 10:59 AM
Last Post: jaseela123d
  source code for task scheduling using genetic algorithm using java 2 8,750 11-04-2017, 08:31 PM
Last Post: Guest
  automatic timetable generator source code vb 1 7,826 07-04-2017, 12:31 PM
Last Post: jaseela123d
Thumbs Up source code of online payment system using steganography and visual cryptography 3 8,729 06-04-2017, 09:56 AM
Last Post: jaseela123d

Forum Jump: