GithubHelp home page GithubHelp logo

java-rsa's Introduction

Java-Rsa

Introduction

I complete this RSA formula in Java by using Biginteger and its self-contained functions.

Workflow

Generate big prime p, q, n and phi(n)

this code first generates a random set of prime number p and q by using the "Security Random()" function and "generateProbablePrime()",
Then calculate the modulus n = q * p and phi(n) = (p -1 )(q - 1).

Generate public key e and private key d

Then select the public key e which is relative prime to the phi(n), by using the function Biginteger.gcd() = 1
and e is in the interval (0, phi(n)).
Here I randomly initiate a new Biginteger with maxium length equaling phi(n) as the value of the public key, and iterate the value of the public key by checking the condition:
publickey.gcd(phi) == 1, and publickey.compareTo(phi(n)) == -1

Encryption & Decryption & Signature & Verification

Encryption: C = M^e mod n, using the modPow() function to calculate directly
Decryption: M = C^e mod n, using the modPow() function to calculate directly
Signature: S = M^d mod n, using the modPow() function to calculate directly
Verification: M = S^e mod n, using the modPow() function to calculate directly

Last Check

In the main functioin, I do the double check that using the .equals() to check if the Message M equals what is decrpted and Cipher text C equals what is encrypted

Demo

Result

java-rsa's People

Contributors

humb1e1989 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.