⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 certificateinfopanel.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                              GridBagConstraints.EAST, 0, row, 1, 1, 0.0, 0.0 );      this.after = new JLabel( " " );      this.after.setHorizontalAlignment( JLabel.LEFT );      this.after.setForeground( Color.black );      this.after.setBorder( commonBorder );      AWTUtilities.constrain( this, this.after, GridBagConstraints.HORIZONTAL,                              GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0 );      lbl = new JLabel( "Algorithm:" );      lbl.setForeground( Color.black );      lbl.setBorder( commonBorder );      AWTUtilities.constrain( this, lbl, GridBagConstraints.NONE,                              GridBagConstraints.EAST, 0, row, 1, 1, 0.0, 0.0,                              new Insets( 23, 0, 0, 0 ) );      this.algorithm = new JLabel( " " );      this.algorithm.setHorizontalAlignment( JLabel.LEFT );      this.algorithm.setForeground( Color.black );      this.algorithm.setBorder( commonBorder );      AWTUtilities.constrain( this, this.algorithm, GridBagConstraints.HORIZONTAL,                              GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0,                              new Insets( 23, 0, 0, 0 ) );      lbl = new JLabel( "Serial Number:" );      lbl.setForeground( Color.black );      lbl.setBorder( commonBorder );      AWTUtilities.constrain( this, lbl, GridBagConstraints.NONE,                              GridBagConstraints.EAST, 0, row, 1, 1, 0.0, 0.0 );      this.serial = new JLabel( " " );      this.serial.setHorizontalAlignment( JLabel.LEFT );      this.serial.setForeground( Color.black );      this.serial.setBorder( commonBorder );      AWTUtilities.constrain( this, this.serial, GridBagConstraints.HORIZONTAL,                              GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0 );      lbl = new JLabel( "Fingerprint:" );      lbl.setForeground( Color.black );      lbl.setBorder( commonBorder );      AWTUtilities.constrain( this, lbl, GridBagConstraints.NONE,                              GridBagConstraints.EAST, 0, row, 1, 1, 0.0, 0.0 );      this.finger = new JLabel( " " );      this.finger.setHorizontalAlignment( JLabel.LEFT );      this.finger.setForeground( Color.black );      this.finger.setBorder( commonBorder );      AWTUtilities.constrain( this, this.finger, GridBagConstraints.HORIZONTAL,                              GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0 );      AWTUtilities.constrain( this, new JPanel(), GridBagConstraints.BOTH,                              GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 1.0 );    }    public void    setCurrentCertificate( X509Certificate cert ) {      Name nm = (Name) cert.getSubjectDN();      String fName = nm.getRDN( ObjectID.friendlyName );      if ( fName == null || fName.length() == 0 )        fName = nm.getRDN( ObjectID.commonName );      if ( fName == null || fName.length() == 0 )        fName = nm.getRDN( ObjectID.organization );      if ( fName == null || fName.length() == 0 )        fName = nm.getRDN( ObjectID.organizationalUnit );      if ( fName == null || fName.length() == 0 )        fName = "Not available";      this.friendlyName.setText( fName );      AlgorithmID signAlg = cert.getSignatureAlgorithm();      this.algorithm.setText( signAlg.getName() );      SimpleDateFormat dFmt = new SimpleDateFormat( "EEE, dd MM yyyy HH:mm:ss" );      Date notBefore = cert.getNotBefore();      Date notAfter = cert.getNotAfter();      String befStr = dFmt.format( notBefore );      String aftStr = dFmt.format( notAfter );      this.before.setText( befStr );      this.after.setText( aftStr );      BigInteger serNum = cert.getSerialNumber();      this.serial.setText( serNum.toString() );      char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',                     'A', 'B', 'C', 'D', 'E', 'F' };      byte[] fBytes = cert.getFingerprint();      StringBuffer buf = new StringBuffer();      for ( int i = 0 ; i < fBytes.length ; ++i ) {        byte b = fBytes[i];                int low = ( b & 15 );        int high = ( (b >> 4) & 15 );        buf.append( hex[high] );        buf.append( hex[low] );      }      this.finger.setText( buf.toString() );    }  }  private class CertDescriptionPanel    extends JPanel  {    private JTextArea    text;    private JScrollPane  scroller;    public    CertDescriptionPanel() {      super();      this.setLayout( new BorderLayout() );      this.text = new JTextArea();      this.scroller = new JScrollPane( text );      this.add( BorderLayout.CENTER, this.scroller );    }    public void    setCurrentCertificate( X509Certificate cert ) {      if ( cert == null ) {        this.text.setText( "" );      } else {        this.text.setText( cert.toString( true ) );      }    }  }  private class CertImportPanel    extends JPanel  {    private JButton  btn;    private JLabel   email;    public    CertImportPanel() {      super();      this.setLayout( new GridBagLayout() );      int row = 0;      JTextArea help = new JTextArea();      help.setText(          "Clicking the import button will add the selected\n"        + "certificate into your list of certificates. This will\n"        + "allow you to send encrypted email to the email\n"        + "address shown with the certificate."        );      help.setOpaque( false );      help.setEditable( false );      this.btn = new JButton( "Import Certificate" );      btn.setActionCommand( "IMPORTCERT" );      btn.addActionListener( CertificateInfoPanel.this );      btn.setEnabled( false );      this.email = new JLabel( "No certificate is selected." );      this.email.setForeground( Color.black );      this.email.setHorizontalAlignment( SwingConstants.CENTER );      JPanel pan = new JPanel();      pan.setLayout( new BorderLayout() );      pan.add( BorderLayout.CENTER, help );      AWTUtilities.constrain( this, pan, GridBagConstraints.NONE,                              GridBagConstraints.SOUTH, 0, 0, 1, 1, 1.0, 0.4 );      AWTUtilities.constrain( this, this.email, GridBagConstraints.HORIZONTAL,                              GridBagConstraints.CENTER, 0, 1, 1, 1, 1.0, 0.0,                              new Insets( 25, 1, 10, 1 ) );      AWTUtilities.constrain( this, this.btn, GridBagConstraints.NONE,                              GridBagConstraints.NORTH, 0, 2, 1, 1, 1.0, 0.6 );    }    public void    setCurrentCertificate( X509Certificate cert ) {      if ( cert == null ) {        this.email.setText( "No certificate is selected." );      } else {        Name nm = (Name) cert.getSubjectDN();        String emailStr = nm.getRDN( ObjectID.emailAddress );        if ( emailStr != null && emailStr.length() > 0 ) {          this.email.setText( emailStr );          this.btn.setEnabled( true );        } else {          this.email.setText( "Selected certificate has no email address." );          this.btn.setEnabled( false );        }      }    }  }  private class CertRDNPanel    extends JPanel  {    private JList        list;    private JScrollPane  scroller;    public    CertRDNPanel() {      super();      this.setLayout( new BorderLayout() );      this.list = new JList();      this.scroller = new JScrollPane( this.list );      this.add( BorderLayout.CENTER, this.scroller );    }    public void    setCurrentCertificate( X509Certificate cert ) {      Name nm = (Name) cert.getSubjectDN();      Vector lv = new Vector();      Enumeration renum = nm.elements();      for ( ; renum.hasMoreElements() ; ) {        RDN r = (RDN) renum.nextElement();        Enumeration aEnum = r.elements();        for ( ; aEnum.hasMoreElements() ; ) {          AVA a = (AVA) aEnum.nextElement();          String val = (String) a.getValue();          String name = a.getType().getShortName();          lv.addElement( name + "=" + val );        }      }      this.list.setListData( lv );    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -