use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.
the class OEncryptionFactory method getEncryption.
public OEncryption getEncryption(final String name, final String iOptions) {
OEncryption encryption = instances.get(name);
if (encryption == null) {
final Class<? extends OEncryption> encryptionClass;
if (name == null)
encryptionClass = ONothingEncryption.class;
else
encryptionClass = classes.get(name);
if (encryptionClass != null) {
try {
encryption = encryptionClass.newInstance();
encryption.configure(iOptions);
} catch (Exception e) {
throw OException.wrapException(new OSecurityException("Cannot instantiate encryption algorithm '" + name + "'"), e);
}
} else
throw new OSecurityException("Encryption with name '" + name + "' is absent");
}
return encryption;
}
use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.
the class OAESEncryption method encryptOrDecrypt.
public byte[] encryptOrDecrypt(final int mode, final byte[] input, final int offset, final int length) throws Exception {
if (!initialized)
throw new OSecurityException("AES encryption algorithm is not available");
cipher.init(mode, theKey);
final byte[] content;
if (offset == 0 && length == input.length) {
content = input;
} else {
content = new byte[length];
System.arraycopy(input, offset, content, 0, length);
}
return cipher.doFinal(content);
}
use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.
the class OAESEncryption method configure.
public OEncryption configure(final String iOptions) {
initialized = false;
if (iOptions == null)
throw new OSecurityException("AES encryption has been selected, but no key was found. Please configure it by passing the key as property at database create/open. The property key is: '" + OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey() + "'");
try {
final byte[] key = OBase64Utils.decode(iOptions);
// AES
theKey = new SecretKeySpec(key, ALGORITHM_NAME);
cipher = Cipher.getInstance(TRANSFORMATION);
} catch (Exception e) {
throw OException.wrapException(new OInvalidStorageEncryptionKeyException("Cannot initialize AES encryption with current key. Assure the key is a BASE64 - 128 oe 256 bits long"), e);
}
this.initialized = true;
return this;
}
use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.
the class ODESEncryption method encryptOrDecrypt.
public byte[] encryptOrDecrypt(final int mode, final byte[] input, final int offset, final int length) throws Exception {
if (!initialized)
throw new OSecurityException("DES encryption algorithm is not available");
cipher.init(mode, theKey);
final byte[] content;
if (offset == 0 && length == input.length) {
content = input;
} else {
content = new byte[length];
System.arraycopy(input, offset, content, 0, length);
}
return cipher.doFinal(content);
}
use of com.orientechnologies.orient.core.exception.OSecurityException in project orientdb by orientechnologies.
the class OIdentifiableIterator method readCurrentRecord.
/**
* Read the current record and increment the counter if the record was found.
*
* @param iRecord
* to read value from database inside it. If record is null link will be created and stored in it.
* @return record which was read from db.
*/
protected ORecord readCurrentRecord(ORecord iRecord, final int iMovement) {
if (limit > -1 && browsedRecords >= limit)
// LIMIT REACHED
return null;
do {
final boolean moveResult;
switch(iMovement) {
case 1:
moveResult = nextPosition();
break;
case -1:
moveResult = prevPosition();
break;
case 0:
moveResult = checkCurrentPosition();
break;
default:
throw new IllegalStateException("Invalid movement value : " + iMovement);
}
if (!moveResult)
return null;
try {
if (iRecord != null) {
ORecordInternal.setIdentity(iRecord, new ORecordId(current.getClusterId(), current.getClusterPosition()));
iRecord = lowLevelDatabase.load(iRecord, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
} else
iRecord = lowLevelDatabase.load(current, fetchPlan, false, true, iterateThroughTombstones, lockingStrategy);
} catch (ODatabaseException e) {
if (Thread.interrupted() || lowLevelDatabase.isClosed())
// THREAD INTERRUPTED: RETURN
throw e;
if (e.getCause() instanceof OSecurityException)
throw e;
OLogManager.instance().error(this, "Error on fetching record during browsing. The record has been skipped", e);
}
if (iRecord != null) {
browsedRecords++;
return iRecord;
}
} while (iMovement != 0);
return null;
}
Aggregations