Results 1 to 3 of 3
  1. #1
    soccermiles is offline Member
    Join Date
    Apr 2010
    Rep Power

    Unhappy Trying to use RSA encryption, failing...

    I am trying to use RSA encryption and I don't know what I'm doing wrong.
    Am I supposed to come up with byte values for each character of the message and put them in a byte[]?:confused:
    Here is the code I'm trying to use (It's triggered by a button in a GUI)
    hopefully there are enough annotations...
    Java Code:
        private void encodeButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
                //making keypairgenerator
            RSAKeyPairGenerator keygen=new RSAKeyPairGenerator();
                //making a secure random to initialize key generator
            SecureRandom rand1=new SecureRandom();
                //initializing keygen
                //naming key pair
            KeyPair keyPair=keygen.generateKeyPair();
                //defining public and private keys, setting text output to show keys
            PublicKey publicKey=keyPair.getPublic();
            PrivateKey privateKey=keyPair.getPrivate();
                //Making cipher object to encode string
            Cipher encipher=Cipher.getInstance("RSA");
                //initializing cipher object
                //defining string to be encoded
            String encode=encodeText.getText();
            byte[] encoded=Cipher.getInstance(encode).doFinal();
                //catching exceptions
            }catch (NoSuchAlgorithmException a) {
               System.err.println("Caught NoSuchAlgorithmException"+a.getMessage());
            }catch (NoSuchPaddingException p) {
               System.err.println("Caught NoSuchPaddingException" + p.getMessage());
            }catch (InvalidKeyException k) {
               System.err.println("Caught InvalidKeyException" + k.getMessage());
            }catch (IllegalBlockSizeException b) {
              System.err.println("Caught IllegalBlockSizeException"+b.getMessage());
            }catch (BadPaddingException bp) {
                System.err.println("Caught BadPaddingException" + bp.getMessage());
    as you can see, there are a LOT OF EXCEPTIONS!!:eek:

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Rep Power


    your code looks good... just in case, take a look at these tutorials: RSA algorithm**Security**Java Tutorial

  3. #3
    soccermiles is offline Member
    Join Date
    Apr 2010
    Rep Power


    thank you for that, it is probably the only good tutorial I have found on this.
    I am actually trying to make a text encoder using a Swing GUI, so I need to fit this all in one method statement.:eek:
    tyty, I will mark as solved if I solve it. Otherwise, if anyone knows why this isnt working, please advise.

Similar Threads

  1. Replies: 0
    Last Post: 02-12-2010, 04:33 PM
  2. EJB invokation failing in jdk1.5.0_23 but works in jdk1.6.0
    By randle169 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 01-28-2010, 10:09 AM
  3. Issues while failing to register ttf fonts.
    By pvn_myne in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 08-19-2009, 09:36 AM
  4. Replies: 0
    Last Post: 02-01-2009, 09:43 AM
  5. Replies: 8
    Last Post: 08-28-2008, 12:48 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts