Package org.ofbiz.entity

Examples of org.ofbiz.entity.EntityCryptoException


    /** Decrypts a hex encoded byte array into a String */
    public Object decrypt(String keyName, String str) throws EntityCryptoException {
        try {
            return UtilObject.getObject(DesCrypt.decrypt(this.getKey(keyName), StringUtil.fromHexString(str)));
        } catch (GeneralException e) {
            throw new EntityCryptoException(e);
        }
    }
View Full Code Here


    protected SecretKey getKeyFromStore(String keyName) throws EntityCryptoException {
        GenericValue keyValue = null;
        try {
            keyValue = delegator.findByPrimaryKey("EntityKeyStore", UtilMisc.toMap("keyName", keyName));
        } catch (GenericEntityException e) {
            throw new EntityCryptoException(e);
        }
        if (keyValue == null || keyValue.get("keyText") == null) {
            SecretKey key = null;
            try {
                key = DesCrypt.generateKey();
            } catch (NoSuchAlgorithmException e) {
                throw new EntityCryptoException(e);
            }
            GenericValue newValue = delegator.makeValue("EntityKeyStore", null);
            newValue.set("keyText", StringUtil.toHexString(key.getEncoded()));
            newValue.set("keyName", keyName);

            Transaction parentTransaction = null;
            boolean beganTrans = false;
            try {
                beganTrans = TransactionUtil.begin();
            } catch (GenericTransactionException e) {
                throw new EntityCryptoException(e);
            }

            if (!beganTrans) {
                try {
                    parentTransaction = TransactionUtil.suspend();
                } catch (GenericTransactionException e) {
                    throw new EntityCryptoException(e);
                }

                // now start a new transaction
                try {
                    beganTrans = TransactionUtil.begin();
                } catch (GenericTransactionException e) {
                    throw new EntityCryptoException(e);
                }
            }

            try {
                delegator.create(newValue);
            } catch (GenericEntityException e) {
                try {
                    TransactionUtil.rollback(beganTrans, "Error creating encrypted value", e);
                } catch (GenericTransactionException e1) {
                    Debug.logError(e1, "Could not rollback transaction", module);
                }
                throw new EntityCryptoException(e);
            } finally {
                try {
                    TransactionUtil.commit(beganTrans);
                } catch (GenericTransactionException e) {
                    throw new EntityCryptoException(e);
                }
                // resume the parent transaction
                if (parentTransaction != null) {
                    try {
                        TransactionUtil.resume(parentTransaction);
                    } catch (GenericTransactionException e) {
                        throw new EntityCryptoException(e);
                    }
                }
            }


            return key;
        } else {
            byte[] keyBytes = StringUtil.fromHexString(keyValue.getString("keyText"));
            try {
                return DesCrypt.getDesKey(keyBytes);
            } catch (GeneralException e) {
                throw new EntityCryptoException(e);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.ofbiz.entity.EntityCryptoException

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.