private EncryptionMetadata extractEncryptionMetadata(byte[] encryptedRecord) throws EncryptionException, IOException, ClassNotFoundException { if (encryptedRecord == null || encryptedRecord.length < MIN_METADATA_LENGTH) { throw new EncryptionException("The encrypted record is too short to contain the metadata"); } // Skip the first byte (SENTINEL) and don't need to copy all the serialized record ByteArrayInputStream bais = new ByteArrayInputStream(encryptedRecord); bais.read(); try (ObjectInputStream ois = new ObjectInputStream(bais)) { return (EncryptionMetadata) ois.readObject(); } }
private Cipher initCipher(EncryptionMethod method, int mode, SecretKey key, byte[] ivBytes) throws EncryptionException { try { if (method == null || key == null || ivBytes == null) { throw new IllegalArgumentException("Missing critical information"); } return aesKeyedCipherProvider.getCipher(method, key, ivBytes, mode == Cipher.ENCRYPT_MODE); } catch (Exception e) { logger.error("Encountered an exception initializing the cipher", e); throw new EncryptionException(e); } }
public EncryptedSchemaRecordWriter(final File file, final AtomicLong idGenerator, final TocWriter writer, final boolean compressed, final int uncompressedBlockSize, final IdentifierLookup idLookup, ProvenanceEventEncryptor provenanceEventEncryptor, int debugFrequency) throws IOException, EncryptionException { super(file, idGenerator, writer, compressed, uncompressedBlockSize, idLookup); this.provenanceEventEncryptor = provenanceEventEncryptor; this.debugFrequency = debugFrequency; try { this.keyId = getNextAvailableKeyId(); } catch (KeyManagementException e) { logger.error("Encountered an error initializing the encrypted schema record writer because the provided encryptor has no valid keys available: ", e); throw new EncryptionException("No valid keys in the provenance event encryptor", e); } }
private byte[] decrypt(byte[] encryptedBytes, String eventId) throws IOException, EncryptionException { try { return provenanceEventEncryptor.decrypt(encryptedBytes, eventId); } catch (Exception e) { logger.error("Encountered an error: ", e); throw new EncryptionException(e); } }
private byte[] encrypt(byte[] serialized, String eventId) throws IOException, EncryptionException { String keyId = getKeyId(); try { return provenanceEventEncryptor.encrypt(serialized, eventId, keyId); } catch (Exception e) { logger.error("Encountered an error: ", e); throw new EncryptionException(e); } }
public byte[] decrypt(byte[] encryptedRecord, String recordId) throws EncryptionException { if (encryptedRecord == null) { throw new EncryptionException("The encrypted provenance record cannot be missing"); final String msg = "Encountered an error reading the encryption metadata: "; logger.error(msg, e); throw new EncryptionException(msg, e); throw new EncryptionException("The event was encrypted with version " + metadata.version + " which is not in the list of supported versions " + StringUtils.join(SUPPORTED_VERSIONS, ",")); throw new EncryptionException("The requested key ID " + metadata.keyId + " is not available"); } else { try { final String msg = "Encountered an exception decrypting provenance record " + recordId; logger.error(msg, e); throw new EncryptionException(msg, e);
public byte[] encrypt(byte[] plainRecord, String recordId, String keyId) throws EncryptionException { if (plainRecord == null || CryptoUtils.isEmpty(keyId)) { throw new EncryptionException("The provenance record and key ID cannot be missing"); throw new EncryptionException("The requested key ID is not available"); } else { byte[] ivBytes = new byte[IV_LENGTH]; final String msg = "Encountered an exception encrypting provenance record " + recordId; logger.error(msg, e); throw new EncryptionException(msg, e);
private EncryptionMetadata extractEncryptionMetadata(byte[] encryptedRecord) throws EncryptionException, IOException, ClassNotFoundException { if (encryptedRecord == null || encryptedRecord.length < MIN_METADATA_LENGTH) { throw new EncryptionException("The encrypted record is too short to contain the metadata"); } // Skip the first byte (SENTINEL) and don't need to copy all the serialized record ByteArrayInputStream bais = new ByteArrayInputStream(encryptedRecord); bais.read(); try (ObjectInputStream ois = new ObjectInputStream(bais)) { return (EncryptionMetadata) ois.readObject(); } }
private Cipher initCipher(EncryptionMethod method, int mode, SecretKey key, byte[] ivBytes) throws EncryptionException { try { if (method == null || key == null || ivBytes == null) { throw new IllegalArgumentException("Missing critical information"); } return aesKeyedCipherProvider.getCipher(method, key, ivBytes, mode == Cipher.ENCRYPT_MODE); } catch (Exception e) { logger.error("Encountered an exception initializing the cipher", e); throw new EncryptionException(e); } }
public byte[] decrypt(byte[] encryptedRecord, String recordId) throws EncryptionException { if (encryptedRecord == null) { throw new EncryptionException("The encrypted provenance record cannot be missing"); final String msg = "Encountered an error reading the encryption metadata: "; logger.error(msg, e); throw new EncryptionException(msg, e); throw new EncryptionException("The event was encrypted with version " + metadata.version + " which is not in the list of supported versions " + StringUtils.join(SUPPORTED_VERSIONS, ",")); throw new EncryptionException("The requested key ID " + metadata.keyId + " is not available"); } else { try { final String msg = "Encountered an exception decrypting provenance record " + recordId; logger.error(msg, e); throw new EncryptionException(msg, e);
public byte[] encrypt(byte[] plainRecord, String recordId, String keyId) throws EncryptionException { if (plainRecord == null || CryptoUtils.isEmpty(keyId)) { throw new EncryptionException("The provenance record and key ID cannot be missing"); throw new EncryptionException("The requested key ID is not available"); } else { byte[] ivBytes = new byte[IV_LENGTH]; final String msg = "Encountered an exception encrypting provenance record " + recordId; logger.error(msg, e); throw new EncryptionException(msg, e);