Package javax.crypto

Examples of javax.crypto.SealedObject


            new LoginFrame();
        }
    }

    private SealedObject showSuperPasswordDialog() {
        SealedObject password = null;
        JPanel panel = new JPanel();
        CellConstraints cc = new CellConstraints();
        panel.setLayout(new FormLayout(
            new ColumnSpec[] {
                    new ColumnSpec("10px"),
                    FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                    new ColumnSpec("150px"),
                    FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                    new ColumnSpec("100px"),
                    FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                    new ColumnSpec("150px")
            },
            new RowSpec[] {
                    new RowSpec("10px"),
                    FormFactory.LINE_GAP_ROWSPEC,
                    new RowSpec("20px"),
                    FormFactory.LINE_GAP_ROWSPEC,
                    new RowSpec("20px"),
            }));
        JLabel superUserPasswordLabel1 = new JLabel();
        superUserPasswordLabel1.setText(TxtManager.getTxt("VIEW.PASSWORDEDIT.SUPERUSERPASSWORDLABEL"));
        panel.add(superUserPasswordLabel1, cc.xy(3, 3));

        JPasswordField superUserPasswordField1 = new JPasswordField();
        panel.add(superUserPasswordField1, cc.xy(5, 3));

        JLabel alertSuperPasswordLabelLabel1 = new JLabel();
        alertSuperPasswordLabelLabel1.setVisible(false);
        panel.add(alertSuperPasswordLabelLabel1, cc.xy(7, 3));

        JLabel superUserPasswordLabel2 = new JLabel();
        superUserPasswordLabel2.setText(TxtManager.getTxt("VIEW.PASSWORDEDIT.NEWPASSWORDLABEL2"));
        panel.add(superUserPasswordLabel2, cc.xy(3, 5));

        JPasswordField superUserPasswordField2 = new JPasswordField();
        panel.add(superUserPasswordField2, cc.xy(5, 5));

        JLabel alertSuperUserPasswordLabel2 = new JLabel();
        alertSuperUserPasswordLabel2.setVisible(false);
        panel.add(alertSuperUserPasswordLabel2, cc.xy(7, 5));
        Object[] options = {TxtManager.getTxt("VIEW.GLOBAL.CONFIRMBUTTON"),
                            TxtManager.getTxt("VIEW.GLOBAL.CANCELBUTTON")};
        int n = -1;
        while ( (n != 0) && (n != 1) ) {
            n = JOptionPane.showOptionDialog(this, panel, TxtManager.getTxt("INFORMATION.CREATESUPERUSERPASSWORD"),
                JOptionPane.OK_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
            if (n == 0) {
                if (superUserPasswordField1.getPassword().length == 0) {
                    alertSuperPasswordLabelLabel1.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                    alertSuperPasswordLabelLabel1.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                    alertSuperPasswordLabelLabel1.setVisible(true);
                    n = -1;
                } else {
                    alertSuperPasswordLabelLabel1.setVisible(false);
                }
                if (superUserPasswordField2.getPassword().length == 0) {
                    alertSuperUserPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                    alertSuperUserPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                    alertSuperUserPasswordLabel2.setVisible(true);
                    n = -1;
                } else {
                    alertSuperUserPasswordLabel2.setVisible(false);
                }
                if (n!= -1) {
                    String newPassword1 = new String(superUserPasswordField1.getPassword());
                    String newPassword2 = new String(superUserPasswordField2.getPassword());
                    if (!newPassword1.equals(newPassword2)) {
                        alertSuperUserPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.PASSWORDNOTEQUAL"));
                        alertSuperUserPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                        alertSuperUserPasswordLabel2.setVisible(true);
                        n = -1;
                    } else {
                        alertSuperUserPasswordLabel2.setVisible(false);
                    }
                }
            }
        }
        if (n == 0) {
            try {
                Cipher cipher = Cipher.getInstance("DES");
                cipher.init(Cipher.ENCRYPT_MODE, GlobalValueManager.getPasswordKey());
                String passwordString = new String(superUserPasswordField1.getPassword());
                password = new SealedObject(passwordString, cipher);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return password;
View Full Code Here


                    ObjectInputStream is = new ObjectInputStream(new FileInputStream(file));
                    Integer stat = (Integer)is.readObject();
                    Vector noEncryData = (Vector)is.readObject();
                    PublicKey publicKey = (PublicKey)is.readObject();
                    byte[] wrappedKey = (byte[])is.readObject();
                    SealedObject encryData = (SealedObject)is.readObject();
                    cixFile = new CixFile(stat, noEncryData, publicKey, wrappedKey, encryData);
                    is.close();
                } catch (Exception e) {
                    return null;
                }
View Full Code Here

                Vector noEncryData = new Vector();
                PublicKey pubKey = null;
                byte[] wrappedKey = null;
                PrivateKey priKey = null;
                Vector encryData = new Vector();
                SealedObject sealedEncryData = null;
                //use the first account's keypair to encry the data;
                Iterator childRowsIter = mainRow.getRowSet().getRows().iterator();
                int currentRow = 0;
                Vector pubKeys = new Vector();
                Vector pas = new Vector();
                while (childRowsIter.hasNext()) {
                    Row childRow = (Row)childRowsIter.next();
                    if (!childRow.isDelete()) {
                        Cell ruserCell = ObjectUtil.findNewCell(childRow, "PA", "RUSER");
                        Cell ruserPaCell = ObjectUtil.findNewCell(childRow, "PA", "RUSERPA");
                       
                        if ( (ruserCell.getColumnValue() != null) && (ruserPaCell.getColumnValue() != null) ) {
                            currentRow++;
                            DAO dao = DAO.getInstance();
                            dao.query(Resources.SELECT_PUBKEY_PRIKEY_FROM_PA_SQL);
                            dao.setObject(1, "ME");
                            dao.setObject(2, ruserCell.getColumnValue());
                            dao.setObject(3, ruserPaCell.getColumnValue());
                            ResultSet rs = dao.executeQuery();
                            try {
                                if (rs.next()) {
                                    if (currentRow == 1) {
                                        pubKey = (PublicKey)rs.getObject("PUBKEY");
                                        priKey = (PrivateKey)rs.getObject("PRIKEY");
                                    }
                                    Cell paCell = ObjectUtil.findNewCell(childRow, "PA", "PA");
                                    pas.add(paCell.getColumnValue());
                                    pubKeys.add(rs.getObject("PUBKEY"));
                                }
                                rs.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }                                               
                    }                       
                }
                encryData.add(mainRow);
                Vector pairData = new Vector();
                pairData.add(pubKeys);
                pairData.add(pas);                       
                encryData.add(pairData);
                try {
                    KeyGenerator keyGen = KeyGenerator.getInstance("DES");
                    SecureRandom random = new SecureRandom();
                    keyGen.init(random);
                    SecretKey key = keyGen.generateKey();
                    Cipher cipher = Cipher.getInstance("DES");
                    cipher.init(Cipher.ENCRYPT_MODE,key);
                    sealedEncryData = new SealedObject(encryData, cipher);                      
                    cipher = Cipher.getInstance("RSA");
                    cipher.init(Cipher.WRAP_MODE, priKey);
                    wrappedKey = cipher.wrap(key);
                } catch (Exception e) {
                    e.printStackTrace();
View Full Code Here

                Vector noEncryData = new Vector();
                PublicKey pubKey = null;
                byte[] wrappedKey = null;
                PrivateKey priKey = null;
                Vector encryData = new Vector();
                SealedObject sealedEncryData = null;
               
                //use the first account's keypair to encry the data;
                Iterator childRowsIter = mainRow.getRowSet().getRows().iterator();
                int currentRow = 0;
                Vector pubKeys = new Vector();
                Vector urpas = new Vector();
                Vector pas = new Vector();
                while (childRowsIter.hasNext()) {
                    Row childRow = (Row)childRowsIter.next();
                    if (!childRow.isDelete()) {
                        Cell ruserCell = ObjectUtil.findNewCell(childRow, "PA", "RUSER");
                        Cell ruserPaCell = ObjectUtil.findNewCell(childRow, "PA", "RUSERPA");
                       
                        if ( (ruserCell.getColumnValue() != null) && (ruserPaCell.getColumnValue() != null) ) {
                            currentRow++;
                            DAO dao = DAO.getInstance();
                            dao.query(Resources.SELECT_PUBKEY_PRIKEY_FROM_PA_SQL);
                            dao.setObject(1, "ME");
                            dao.setObject(2, ruserCell.getColumnValue());
                            dao.setObject(3, ruserPaCell.getColumnValue());
                            ResultSet rs = dao.executeQuery();
                            try {
                                if (rs.next()) {
                                    if (currentRow == 1) {
                                        pubKey = (PublicKey)rs.getObject("PUBKEY");
                                        priKey = (PrivateKey)rs.getObject("PRIKEY");
                                    }
                                    Cell urpaCell = ObjectUtil.findNewCell(childRow, "PA", "URPA");
                                    Cell paCell = ObjectUtil.findNewCell(childRow, "PA", "PA");
                                    if ( (urpaCell.getColumnValue() != null) && (!((String)urpaCell.getColumnValue()).trim().equals("")) ) {
                                        pubKeys.add(rs.getObject("PUBKEY"));
                                        urpas.add(urpaCell.getColumnValue());
                                        pas.add(paCell.getColumnValue());
                                    }
                                }
                                rs.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }                                               
                    }                       
                }
                encryData.add(mainRow);
                Vector pairData = new Vector();
                pairData.add(pubKeys);
                pairData.add(pas);
                pairData.add(urpas);
                encryData.add(pairData);
                try {
                    KeyGenerator keyGen = KeyGenerator.getInstance("DES");
                    SecureRandom random = new SecureRandom();
                    keyGen.init(random);
                    SecretKey key = keyGen.generateKey();
                    Cipher cipher = Cipher.getInstance("DES");
                    cipher.init(Cipher.ENCRYPT_MODE,key);
                    sealedEncryData = new SealedObject(encryData, cipher);                      
                    cipher = Cipher.getInstance("RSA");
                    cipher.init(Cipher.WRAP_MODE, priKey);
                    wrappedKey = cipher.wrap(key);
                } catch (Exception e) {
                    e.printStackTrace();
View Full Code Here

                                alertSuperPasswordLabelLabel.setText(TxtManager.getTxt("VALIDATE.PASSWORDERROR"));
                                alertSuperPasswordLabelLabel.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                alertSuperPasswordLabelLabel.setVisible(true);
                            } else {
                                String oldPassword = null;
                                SealedObject so = (SealedObject)value;                       
                                try {
                                    oldPassword = PasswordManager.getPassword(so);                           
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                StringBuffer sb = new StringBuffer(TxtManager.getTxt("INFORMATION.SHOWPASSWORD"));
                                sb.append(oldPassword + " !");
                                DialogManager.showMessageDialog(this, sb.toString());
                            }
                        }
                    }
                } else if (n == 0) {
                    if (createNewPassword) {
                        if (newPasswordField1.getPassword().length == 0) {
                            alertNewPasswordLabel1.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                            alertNewPasswordLabel1.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                            alertNewPasswordLabel1.setVisible(true);
                            n = -1;
                        } else {
                            alertNewPasswordLabel1.setVisible(false);
                        }
                        if (newPasswordField2.getPassword().length == 0) {
                            alertNewPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                            alertNewPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                            alertNewPasswordLabel2.setVisible(true);
                            n = -1;
                        } else {
                            alertNewPasswordLabel2.setVisible(false);
                        }
                        if (n!= -1) {
                            String newPassword1 = new String(newPasswordField1.getPassword());
                            String newPassword2 = new String(newPasswordField2.getPassword());
                            if (!newPassword1.equals(newPassword2)) {
                                alertNewPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.PASSWORDNOTEQUAL"));
                                alertNewPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                alertNewPasswordLabel2.setVisible(true);
                                n = -1;
                            } else {
                                alertNewPasswordLabel2.setVisible(false);
                            }
                        }
                    } else {
                        if (superUserPasswordField.getPassword().length == 0) {                       
                            String oldPassword = null;
                            SealedObject so = (SealedObject)value;                       
                            try {
                                oldPassword = PasswordManager.getPassword(so);                           
                            } catch (Exception e) {
                                e.printStackTrace();
                            }                            
                            if (oldPasswordField.getPassword().length == 0) {
                                alertOldPasswordLabel.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                                alertOldPasswordLabel.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                alertOldPasswordLabel.setVisible(true);
                                n=-1;
                            } else {
                                String oldPassword1 = new String(oldPasswordField.getPassword());
                                if (!oldPassword.equals(oldPassword1)) {
                                    alertOldPasswordLabel.setText(TxtManager.getTxt("VALIDATE.PASSWORDERROR"));
                                    alertOldPasswordLabel.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                    alertOldPasswordLabel.setVisible(true);
                                    n=-1;
                                } else {
                                    alertOldPasswordLabel.setVisible(false);
                                }
                            }
                            if (newPasswordField1.getPassword().length == 0) {
                                alertNewPasswordLabel1.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                                alertNewPasswordLabel1.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                alertNewPasswordLabel1.setVisible(true);
                                n = -1;
                            } else {
                                alertNewPasswordLabel1.setVisible(false);
                            }
                            if (newPasswordField2.getPassword().length == 0) {
                                alertNewPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                                alertNewPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                alertNewPasswordLabel2.setVisible(true);
                                n = -1;
                            } else {
                                alertNewPasswordLabel2.setVisible(false);
                            }
                            if (n != -1) {
                                String newPassword1 = new String(newPasswordField1.getPassword());
                                String newPassword2 = new String(newPasswordField2.getPassword());
                                if (!newPassword1.equals(newPassword2)) {
                                    alertNewPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.PASSWORDNOTEQUAL"));
                                    alertNewPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                    alertNewPasswordLabel2.setVisible(true);
                                    n = -1;
                                } else {
                                    alertNewPasswordLabel2.setVisible(false);
                                }
                            }                           
                        } else {
                            alertOldPasswordLabel.setVisible(false);
                            if (newPasswordField1.getPassword().length == 0) {
                                alertNewPasswordLabel1.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                                alertNewPasswordLabel1.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                alertNewPasswordLabel1.setVisible(true);
                                n = -1;
                            } else {
                                alertNewPasswordLabel1.setVisible(false);
                            }
                            if (newPasswordField2.getPassword().length == 0) {
                                alertNewPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.NULLVALUE"));
                                alertNewPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                alertNewPasswordLabel2.setVisible(true);
                                n = -1;
                            } else {
                                alertNewPasswordLabel2.setVisible(false);
                            }
                            if (n != -1) {
                                String newPassword1 = new String(newPasswordField1.getPassword());
                                String newPassword2 = new String(newPasswordField2.getPassword());
                                if (!newPassword1.equals(newPassword2)) {
                                    alertNewPasswordLabel2.setText(TxtManager.getTxt("VALIDATE.PASSWORDNOTEQUAL"));
                                    alertNewPasswordLabel2.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                    alertNewPasswordLabel2.setVisible(true);
                                    n = -1;
                                } else {
                                    alertNewPasswordLabel2.setVisible(false);
                                }
                            }
                            if (n != -1) {
                                String superUserPassword1 = new String(superUserPasswordField.getPassword());
                                String superUserPassword = UserClass.getSuperUserPassword();
                                if (!superUserPassword.equals(superUserPassword1)) {                                   
                                    alertSuperPasswordLabelLabel.setText(TxtManager.getTxt("VALIDATE.PASSWORDERROR"));
                                    alertSuperPasswordLabelLabel.setIcon(ImageManager.getImage(ImageManager.ALERT_IMAGE));
                                    alertSuperPasswordLabelLabel.setVisible(true);
                                    n=-1;
                                } else {
                                    alertSuperPasswordLabelLabel.setVisible(false);
                                }
                            }
                        }                                               
                    }
                }
            }
            if (n == 0) {
                try {
                    Cipher cipher = Cipher.getInstance("DES");
                    cipher.init(Cipher.ENCRYPT_MODE, GlobalValueManager.getPasswordKey());
                    String password = new String(newPasswordField1.getPassword());
                    SealedObject so = new SealedObject(password, cipher);
                    setValue(so);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
View Full Code Here

    public static String getSuperUserPassword() {

            String password = null;
            Row superUserRow = UserClass.getSuperUser();
            if (superUserRow != null) {
                SealedObject so = (SealedObject)ObjectUtil.findNewCell(superUserRow, "RUSER", "PASSWORD").getColumnValue();
                try {
                    password = PasswordManager.getPassword(so);
                } catch (Exception e) {
                    e.printStackTrace();
                }
View Full Code Here

    public String encrypt(Serializable source) {
        SecretKeySpec spec = getSecretKeySpec();
        try {
            Cipher c = Cipher.getInstance(spec.getAlgorithm());
            c.init(Cipher.ENCRYPT_MODE, spec);
            SealedObject so = new SealedObject(source, c);
            ByteArrayOutputStream store = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(store);
            out.writeObject(so);
            out.close();
            byte[] data = store.toByteArray();
View Full Code Here

        try {
            byte[] data = Base64.decode(source);
            Cipher c = Cipher.getInstance(spec.getAlgorithm());
            c.init(Cipher.DECRYPT_MODE, spec);
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
            SealedObject so = (SealedObject) in.readObject();
            return (Serializable) so.getObject(c);
        } catch (Exception e) {
            log.error("Unable to decrypt", e);
            return null;
        }
    }
View Full Code Here

/*     */       }
/*     */       else
/*     */       {
/* 562 */         cipher.init(1, skey);
/*     */       }
/* 564 */       sealedObject = new SealedObject(data, cipher);
/*     */     }
/*     */     catch (GeneralSecurityException e)
/*     */     {
/* 568 */       throw e;
/*     */     }
View Full Code Here

/*     */       }
/*     */       else
/*     */       {
/* 593 */         cipher.init(2, skey);
/*     */       }
/* 595 */       SealedObject sealedObj = (SealedObject)obj;
/* 596 */       data = sealedObj.getObject(cipher);
/*     */     }
/*     */     catch (GeneralSecurityException e)
/*     */     {
/* 600 */       throw e;
/*     */     }
View Full Code Here

TOP

Related Classes of javax.crypto.SealedObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.