3 Replies Latest reply: Apr 14, 2013 4:44 AM by EJP RSS

    Error: "RSA premaster secret error"

    1002884
      Here is my Code.
      import java.sql.DriverManager;
      import java.sql.Connection;
      import java.awt.Button;
      import java.awt.Component;
      import java.awt.Container;
      import javax.swing.JOptionPane;
      import java.awt.Frame;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.*;
      import javax.swing.AbstractButton;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JTextField;
      import javax.swing.SpringLayout;
      
      public class SpringSample extends Frame implements ActionListener
      
      {
           
            JLabel F_namelbl = new JLabel("Firstname: ");
               JLabel L_namelbl = new JLabel("Lastname: ");
               JTextField tf_Fname = new JTextField(15);
               JTextField tf_Lname = new JTextField(15);
               JLabel Lbl_HW = new JLabel("< Login Area >");
               JButton Btn = new JButton("Login");
               JButton btn_cancel = new JButton("Cancel");
           
           /**
            * 
            */
           private static final long serialVersionUID = 1L;
           
           SpringSample()
           {
                
               
                 JFrame frame = new JFrame("Login Area!");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    Container contentPane = frame.getContentPane();
                    JPanel p = new JPanel(new SpringLayout());
                    SpringLayout layout = (new SpringLayout());
                    contentPane.setLayout(layout);             
                    JPanel p1=new JPanel();    
                  
                     
                 
                    
                    JLabel F_namelbl = new JLabel("Firstname: ");
                    JLabel L_namelbl = new JLabel("Lastname: ");
                    JTextField tf_Fname = new JTextField(15);
                    JTextField tf_Lname = new JTextField(15);
                    JLabel Lbl_HW = new JLabel("< Login Area >");
                    JButton Btn = new JButton("Login");
                    JButton btn_cancel = new JButton("Cancel");*/
                    
                 
                    frame.add(p1);
                    contentPane.add(F_namelbl);
                    contentPane.add(L_namelbl);
                    contentPane.add(tf_Fname);
                    contentPane.add(tf_Lname);
                    contentPane.add(Lbl_HW);
                    contentPane.add(Btn);
                    contentPane.add(btn_cancel);
                             
                   
                    
                    layout.putConstraint(SpringLayout.WEST, Lbl_HW, 140, SpringLayout.WEST, contentPane);
                    layout.putConstraint(SpringLayout.NORTH, Lbl_HW, 0, SpringLayout.NORTH, contentPane);    
                    layout.putConstraint(SpringLayout.WEST, Lbl_HW, 140, SpringLayout.WEST, contentPane);
                    layout.putConstraint(SpringLayout.NORTH, Lbl_HW, 0, SpringLayout.NORTH, contentPane);
                    layout.putConstraint(SpringLayout.WEST, F_namelbl, 30, SpringLayout.WEST, contentPane);
                    layout.putConstraint(SpringLayout.NORTH, F_namelbl, 25, SpringLayout.NORTH, contentPane);
                    layout.putConstraint(SpringLayout.WEST, L_namelbl, 30, SpringLayout.WEST, contentPane);
                    layout.putConstraint(SpringLayout.NORTH, L_namelbl, 50, SpringLayout.NORTH, contentPane);
                    layout.putConstraint(SpringLayout.NORTH, tf_Fname, 25, SpringLayout.NORTH, contentPane);
                    layout.putConstraint(SpringLayout.WEST, tf_Fname, 15, SpringLayout.EAST, F_namelbl);
                    layout.putConstraint(SpringLayout.NORTH, tf_Lname, 50, SpringLayout.NORTH, contentPane);
                    layout.putConstraint(SpringLayout.WEST, tf_Lname, 15, SpringLayout.EAST, F_namelbl);
                    layout.putConstraint(SpringLayout.NORTH, Btn, 80, SpringLayout.NORTH, contentPane);
                    layout.putConstraint(SpringLayout.WEST, Btn, 110, SpringLayout.WEST, contentPane);
                    layout.putConstraint(SpringLayout.NORTH, btn_cancel, 80, SpringLayout.NORTH, p1);
                    layout.putConstraint(SpringLayout.WEST, btn_cancel, 200, SpringLayout.WEST, p1);         
                    
                  
                    btn_cancel.addActionListener(this);
                    Btn.addActionListener(this);
                    
                  
                    
                    frame.pack();
                    frame.setSize(350, 200);
                    frame.setVisible(true);     
           }
        public static void main(String args[]) 
        {      
         
          new SpringSample();
          Connection con = ConnectionDB.DBConnectionstring();  //ON THIS LINE GETTING AN ERROR
          
        }
      
       public void actionPerformed(ActionEvent e) 
      {
            //Object source = e.getSource();
           if(e.getSource() == btn_cancel){
                JOptionPane.showMessageDialog(null,"You have clicked on Cancel","button cancel",JOptionPane.WARNING_MESSAGE);
           }
           else if(e.getSource() == Btn){
                JOptionPane.showMessageDialog(null,"You have clicked login","button login",JOptionPane.WARNING_MESSAGE);          
           }
           //System.out.println("Hello There");
           //JOptionPane.showMessageDialog(null,"ALERT MESSAGE","TITLE",JOptionPane.WARNING_MESSAGE);
      
      }
      }
      ERROR:
      Apr 13, 2013 8:29:49 PM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
      INFO: java.security path: C:\Program Files\Java\jdk1.7.0_17\jre\lib\security
      Security providers: [SUN version 1.7, SunRsaSign version 1.7, SunEC version 1.7, SunJSSE version 1.7, SunJCE version 1.7, SunJGSS version 1.7, SunSASL version 1.7, XMLDSig version 1.0, SunPCSC version 1.7, SunMSCAPI version 1.7]
      SSLContext provider info: Sun JSSE provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
      SSLContext provider services:
      [SunJSSE: KeyFactory.RSA -> sun.security.rsa.RSAKeyFactory
        aliases: [1.2.840.113549.1.1, OID.1.2.840.113549.1.1]
      , SunJSSE: KeyPairGenerator.RSA -> sun.security.rsa.RSAKeyPairGenerator
        aliases: [1.2.840.113549.1.1, OID.1.2.840.113549.1.1]
      , SunJSSE: Signature.MD2withRSA -> sun.security.rsa.RSASignature$MD2withRSA
        aliases: [1.2.840.113549.1.1.2, OID.1.2.840.113549.1.1.2]
      , SunJSSE: Signature.MD5withRSA -> sun.security.rsa.RSASignature$MD5withRSA
        aliases: [1.2.840.113549.1.1.4, OID.1.2.840.113549.1.1.4]
      , SunJSSE: Signature.SHA1withRSA -> sun.security.rsa.RSASignature$SHA1withRSA
        aliases: [1.2.840.113549.1.1.5, OID.1.2.840.113549.1.1.5, 1.3.14.3.2.29, OID.1.3.14.3.2.29]
      , SunJSSE: Signature.MD5andSHA1withRSA -> sun.security.ssl.RSASignature
      , SunJSSE: KeyManagerFactory.SunX509 -> sun.security.ssl.KeyManagerFactoryImpl$SunX509
      , SunJSSE: KeyManagerFactory.NewSunX509 -> sun.security.ssl.KeyManagerFactoryImpl$X509
        aliases: [PKIX]
      , SunJSSE: TrustManagerFactory.SunX509 -> sun.security.ssl.TrustManagerFactoryImpl$SimpleFactory
      , SunJSSE: TrustManagerFactory.PKIX -> sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory
        aliases: [SunPKIX, X509, X.509]
      , SunJSSE: SSLContext.TLSv1 -> sun.security.ssl.SSLContextImpl$TLS10Context
        aliases: [TLS, SSL, SSLv3]
      , SunJSSE: SSLContext.TLSv1.1 -> sun.security.ssl.SSLContextImpl$TLS11Context
      , SunJSSE: SSLContext.TLSv1.2 -> sun.security.ssl.SSLContextImpl$TLS12Context
      , SunJSSE: SSLContext.Default -> sun.security.ssl.SSLContextImpl$DefaultSSLContext
      , SunJSSE: KeyStore.PKCS12 -> sun.security.pkcs12.PKCS12KeyStore
      ]
      java.ext.dirs: C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
      com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "RSA premaster secret error". ClientConnectionId:3f6f7793-611b-4cfc-8122-e6ffde9b0c69
           at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
           at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1668)
           at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1323)
           at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
           at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
           at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
           at java.sql.DriverManager.getConnection(Unknown Source)
           at java.sql.DriverManager.getConnection(Unknown Source)
           at ConnectionDB.DBConnectionstring(ConnectionDB.java:98)
           at SpringSample.main(SpringSample.java:107)
      Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error
           at sun.security.ssl.RSAClientKeyExchange.<init>(Unknown Source)
           at sun.security.ssl.ClientHandshaker.serverHelloDone(Unknown Source)
           at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
           at sun.security.ssl.Handshaker.processLoop(Unknown Source)
           at sun.security.ssl.Handshaker.process_record(Unknown Source)
           at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
           at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
           at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
           at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
           at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1618)
           ... 8 more
      Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
           at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:158)
           at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:207)
           at sun.security.ssl.JsseJce.getKeyGenerator(Unknown Source)
           ... 18 more
      I am using Eclipse Juno

      Edited by: 999881 on Apr 13, 2013 8:11 AM