1 / 16

Java Program to Implement RSA Algorithm Yu-Li Chen

Java Program to Implement RSA Algorithm Yu-Li Chen April, 2002. RSA: public key cryptographic system algorithm of RSA is openly published much slower than encrypting with a secret key provides both confidentiality and digital signing functions

cecil
Download Presentation

Java Program to Implement RSA Algorithm Yu-Li Chen

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Program to Implement RSA Algorithm Yu-Li Chen April, 2002

  2. RSA: • public key cryptographic system • algorithm of RSA is openly published • much slower than encrypting with a secret key • provides both confidentiality and digital signing functions • mostly used for authentication and exchanging a secret key

  3. The RSA algorithm: • Key generation • Encryption with public key • Decryption with private key

  4. Key generation • Select p,q p and q both prime • Calculate n = p*q • Calculate (n)=(p-1)(q-1) • Select integer gcd ((n),e)=1; 1<e<(n) • Calculate d e*d=1 mod (n) • Public key Kpublic={e,n} • Private key Kprivarte={d,n}

  5. Encryption • Plaintext: M<n • eCiphertext: C=M mode n

  6. Decryption • Ciphertext: C • d • Plaintext: M=C mode n

  7. Objectives: • Write a Java program to implement RSA algorithm • After public key and private key been generated, use Alice/Bob application over TCP to demonstrate encryption and decryption process.

  8. Method: • Alice class: • Generate the public key pair (1024 bit) and send to Bob. • Decrypt the message received from Bob • Bob class: • Receive public key from Alice • Use the public key to encrypt the message • Send the ciphertext to Alice.

  9. Alice: bitLength = 512; certainty = 50; rnd = new SecureRandom(); p = new BigInteger(bitLength, certainty, rnd); q = new BigInteger(bitLength,certainty,rnd); n= p.multiply(q); one= new BigInteger("1"); x = p.subtract(one).multiply(q.subtract(one)); e = new BigInteger("65537"); d = e.modInverse(x);

  10. Alice: Socket clientSocket = new Socket(hostname, 6789); DataOutputStream outToBob =new DataOutputStream(clientSocket.getOutputStream()); outToBob.writeBytes(publicKey + '\n'); clientSocket.close();

  11. Bob: ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromAlice =new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); publicKey = inFromAlice.readLine(); publickyText.setText(publicKey); }

  12. Bob: n= new BigInteger(publicKey); e = new BigInteger("65537"); plaintext=plainText.getText(); m= new BigInteger(plaintext); c = m.modPow(e,n); ciphertext=c.toString();

  13. Bob: Socket clientSocket = new Socket(hostname, 2345); DataOutputStream outToAlice = new DataOutputStream( clientSocket.getOutputStream()); outToAlice.writeBytes(ciphertext); clientSocket.close();

  14. Alice: ServerSocket welcomeSocket = new ServerSocket(2345); while(true) { Socket connectionSocket= welcomeSocket.accept(); BufferedReader inFromBob = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); cipher=inFromBob.readLine(); cipherText.setText(cipher); c= new BigInteger(cipher); m=c.modPow(d,n);

More Related