Author: doogie
Date: Fri May 4 21:58:24 2012
New Revision: 1334213
URL:
http://svn.apache.org/viewvc?rev=1334213&view=revLog:
OPTIMIZE: Move the 2 similiar blocks of key/value decryption code in
decrypt() into a separate internal helper method.
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java?rev=1334213&r1=1334212&r2=1334213&view=diff==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityCrypto.java Fri May 4 21:58:24 2012
@@ -89,17 +89,12 @@ public class EntityCrypto {
Object decryptedObj = null;
byte[] encryptedBytes = StringUtil.fromHexString(encryptedString);
try {
- SecretKey decryptKey = this.findKey(keyName, false);
- byte[] decryptedBytes = DesCrypt.decrypt(decryptKey, encryptedBytes);
-
- decryptedObj = UtilObject.getObject(decryptedBytes);
+ decryptedObj = doDecrypt(keyName, encryptedBytes, false);
} catch (GeneralException e) {
try {
// try using the old/bad hex encoding approach; this is another path the code may take, ie if there is an exception thrown in decrypt
Debug.logInfo("Decrypt with DES key from standard key name hash failed, trying old/funny variety of key name hash", module);
- SecretKey decryptKey = this.findKey(keyName, true);
- byte[] decryptedBytes = DesCrypt.decrypt(decryptKey, encryptedBytes);
- decryptedObj = UtilObject.getObject(decryptedBytes);
+ decryptedObj = doDecrypt(keyName, encryptedBytes, false);
//Debug.logInfo("Old/funny variety succeeded: Decrypted value [" + encryptedString + "]", module);
} catch (GeneralException e1) {
// NOTE: this throws the original exception back, not the new one if it fails using the other approach
@@ -111,6 +106,12 @@ public class EntityCrypto {
return decryptedObj;
}
+ protected Object doDecrypt(String keyName, byte[] encryptedBytes, boolean useOldFunnyKeyHash) throws GeneralException {
+ SecretKey decryptKey = this.findKey(keyName, false);
+ byte[] decryptedBytes = DesCrypt.decrypt(decryptKey, encryptedBytes);
+ return UtilObject.getObject(decryptedBytes);
+ }
+
protected SecretKey findKey(String originalKeyName, boolean useOldFunnyKeyHash) throws EntityCryptoException {
String keyMapName = originalKeyName + useOldFunnyKeyHash;
synchronized (keyMap) {