encryption - RSA Enabled Simple Java Chat - Not PKCS#1 block type 2 or Zero padding -


I have created a simple Java chat application below to follow

chat client. Run Java - The dialog box is displayed where the user enters the user name. Then the private key and the public key is created and stored in C / Username / PublicKi, C: / Username / Pivetakic.

When we re-run the Chatecolient Java, the phase repeats.

Then User2 encrypts the user2 in a encrypted form using the User2 public key (which is working fine) (after encryption, the message is stored in the text file), then user 2 Clicks the decrypt button that decrypt text (reads encrypted text using User 2) Private key is displayed in TextRena.

When I try to decrypt, I can not find the "PKCS # 1 block type 2 or zero padding" exception

  public static byte [] encrypt (String text, the key of the public) {// Receive an RSA cipher object and the last cipher cipher = cipher to the provider. Print Get Instance (Algorithm); // Encrypt plain text using public key cipher.init (cipher NCRIPTMMEE, key); Byte [] ciphertext = cipher.dominal (text.getbits ("UTF8"); Return org.apache.commons.codec.binary.Base64.encodeBase64 (cipher text); } Public static string decrypt throws (string text, private key) {byte [dectyptedText = null; // Receive an RSA cipher object and print the provider last cipher cipher = cipher Gate instence (algorithm); // Decrypt the text using the private key cipher.init (cipher DECRAPTMMEE, key); Byte [] bytefiletext = org.apache.commons.codec.binary.Base64.decodeBase64 (text): byte [] cipherdata = cipher.domain (byte cipher text); Return a new string (decrypted text); } Private Zero throws btnDecryptActionPerformed (ActionEvent evt) {String name11 = this.getTitle (); String test90 = faucet; String PRIVATE_KEY_FILE = "C: / keys /" + name11 + "/ private.key"; Buffet = thread in the thread; Try {New == BufferedReader (New FileReader ("cipher.txt")); } Hold (FileNotFoundException e1) {// TODO Auto-Generated Cache Block e1.printStackTrace (); } Try {while (in.ready ()) {String stest = in.readLine (); Test90 = idiot; }} Catch (IOE EXPRESS E1) {// Todo Auto-Generate Cache Block e1.printStackTrace (); } ObjectInputStream inputstream = faucet; {InputStream = Try New Object Instestream (New File InStstream (PRIVATE_KEY_FILE)); } Hold (FileNotFoundException e1) {// TODO Auto-Generated Cache Block e1.printStackTrace (); } Grip (IOException e1) {// TODO Auto-generated Cache Block e1.printStackTrace (); } Private personal = null; Try {privateKey = (PrivateKey) inputStream.readObject (); } Catch (Clasnotfoundive Express E1) {// Todo Auto-Generate Cache Block e1.printStackTrace (); } Grip (IOException e1) {// TODO Auto-generated Cache Block e1.printStackTrace (); } Try {InputStream = new ObjectInputStream (New FileInputStream (PRIVATE_KEY_FILE)); } Hold (FileNotFoundException E) {// TODO Auto generated blocking block e.printStackTrace (); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); } {Private private key = (private) Try inputStream.readObject (); } Catch (Clasnostfundai Express E) {// To-O Auto-Generated Catch Block e.printStackTrace (); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); } Plain plain text; // byte [] test100 = test90.getBytes (); // out.println (test100); Plain text = decrypt (test 90, personal); (Get error here) decrypt text .append (plain text); }   

Highlight code below test90 only included The last line in the cipher.txt file. Is there only 1 line in cipher.txt? If you want to read everything, then you have to add each line as you have read it.

  while (in.ready ()) {string string = in.readLine (); Test90 = idiot; }   

This is a good idea in the system.out variable test90 in the decrypt method For that the expected base 64 data is being decrypted to you.

Comments

Popular posts from this blog

How can I add a seperate action listener to all 14 of my buttons at once that can determine player turn?(java) -

Simple file compression in C -

php - Sorting an multidimension array using usort fails -