What am I trying to encrypt the current date and time with RSA and enter other applications to authenticate Use this cipher text to the user.
Here's the code I'm not a noob with Java, so I copied it from the Internet and made some changes.
Program -
import java.math.BigInteger; Import java.security.SecureRandom; Import java.util.Scanner; Import java.util.Date; Import java.text.DateFormat; Import java.text.SimpleDateFormat; Import java.util.Calendar; Public class RSA3 (Public BigInteger n, D, E; Private Entitlement = 16; / ** Create an example that can both be encrypted and decrypted * / Public RSA3 (int bit) {bitlen = bit; safe reserved R = New SecureRandem (); Scanner = New Scanner (System.in); String Number 1, Number2; System.out.println ("Enter First Number"); Number1 = in.nextLine (); System.out Println ("Enter second number"); Number2 = in.nextLine (); Bigenter P = new BigInteger (number1); B Giantage q = New BigInteger (number 2); // BigInterior Page = New Bigteger (Bitlan / 2,100, R); // BigInterator q = New BigIntega (Bittern / 2,100, R); N = p.multiply (q); System .out.println ("\ nn =" + n); Bigiteger M = (P. Suebatactor (BigEngager.on). Multiplication (q.subtract (BigInteger.one)); System.out.println ("\ nM = "+ M); e = new bigigner (" 3 "); while (m.gcd (e) .intValue ()> 1) {e = ed. (New BigInteger (" 2 "));} System.out.println ("\ nE =" + E); D = e.modInverse (m); System.out.println ("\ nD =" + D);} / ** Plain text message given Encrypt * / bit Wajnik synchronize encrypted BigInteger (BigInteger message) {System.out.println ( "\ n 2 encoded"); Return message. Modpow (e, n); } / ** Decrypt the given ciphertext message * / Public synchronized BigEnger decrypt (BigInter Message) {System.out.println ("\ n2nd dec"); Return message. Maandpou (D, N); } / ** trivial testing program. * / Public static zero main (string [] args) {RSA3 RSA = new RSA3 (1024); Date format date format = new simpleadformat ("yymymdhd"); // Get the current date time with date () date = date new date (); Println (dateFormat.format (date)); String Text 1 = Datformat. Format (date); System.out.println ("plaintext:" + text1); Bigtitar plain text = new bigigner (text1 bullets ()); Bigtegger ciphertext = RSA encrypt (plain text); System.out.println ("Cybertext:" + Ciphertext); Plain Text = RSA Decrypt (ciphertext); String Text 2 = New String (Simple Text to Two Arrays); System.out.println ("plaintext:" + text2); }}
If I take the value for P & A; The user has q as I have done in the code. Some are wrong with ciphertext but if I go with BigInteger (Bitlen / 2,100, R); It's working fine but with this random number every time ciphertex generating is new. I do not want this way me p & amp; My own choice q
I think I have done something bad with the biggieger. Please tell me that I can do it any other way.
I could not find a logical error here, please thank you
No comments:
Post a Comment