Search in sources :

Example 1 with OInvalidStorageEncryptionKeyException

use of com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException in project orientdb by orientechnologies.

the class ODESEncryption method configure.

public OEncryption configure(final String iOptions) {
    initialized = false;
    if (iOptions == null)
        throw new OSecurityException("DES 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);
        final DESKeySpec desKeySpec = new DESKeySpec(key);
        final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM_NAME);
        theKey = keyFactory.generateSecret(desKeySpec);
        cipher = Cipher.getInstance(TRANSFORMATION);
    } catch (Exception e) {
        throw OException.wrapException(new OInvalidStorageEncryptionKeyException("Cannot initialize DES encryption with current key. Assure the key is a BASE64 - 64 bits long"), e);
    }
    this.initialized = true;
    return this;
}
Also used : OInvalidStorageEncryptionKeyException(com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) DESKeySpec(javax.crypto.spec.DESKeySpec) SecretKeyFactory(javax.crypto.SecretKeyFactory) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OInvalidStorageEncryptionKeyException(com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException) OException(com.orientechnologies.common.exception.OException)

Example 2 with OInvalidStorageEncryptionKeyException

use of com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException 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;
}
Also used : OInvalidStorageEncryptionKeyException(com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OInvalidStorageEncryptionKeyException(com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException) OException(com.orientechnologies.common.exception.OException)

Aggregations

OException (com.orientechnologies.common.exception.OException)2 OInvalidStorageEncryptionKeyException (com.orientechnologies.orient.core.exception.OInvalidStorageEncryptionKeyException)2 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)2 SecretKeyFactory (javax.crypto.SecretKeyFactory)1 DESKeySpec (javax.crypto.spec.DESKeySpec)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1