Search in sources :

Example 1 with RepeatableCipherInputStream

use of com.amazonaws.services.s3.internal.RepeatableCipherInputStream in project aws-sdk-android by aws-amplify.

the class EncryptionUtils method decryptObjectUsingInstruction.

/**
 * Returns an updated object where the object content input stream contains
 * the decrypted contents.
 *
 * @param object The object whose contents are to be decrypted.
 * @param instruction The instruction that will be used to decrypt the
 *            object data.
 * @return The updated object where the object content input stream contains
 *         the decrypted contents.
 */
public static S3Object decryptObjectUsingInstruction(S3Object object, EncryptionInstruction instruction) {
    S3ObjectInputStream objectContent = object.getObjectContent();
    InputStream decryptedInputStream = new RepeatableCipherInputStream(objectContent, instruction.getCipherFactory());
    object.setObjectContent(new S3ObjectInputStream(decryptedInputStream));
    return object;
}
Also used : RepeatableCipherInputStream(com.amazonaws.services.s3.internal.RepeatableCipherInputStream) LengthCheckInputStream(com.amazonaws.util.LengthCheckInputStream) RepeatableFileInputStream(com.amazonaws.services.s3.internal.RepeatableFileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) RepeatableCipherInputStream(com.amazonaws.services.s3.internal.RepeatableCipherInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream)

Example 2 with RepeatableCipherInputStream

use of com.amazonaws.services.s3.internal.RepeatableCipherInputStream in project aws-sdk-android by aws-amplify.

the class EncryptionUtils method getEncryptedInputStream.

/**
 * Retrives the encrypted input stream.
 * @param request the UploadPartRequest to encrypt.
 * @param cipherFactory the CipherFactory used to encrypt.
 * @return the encrypted input stream.
 */
public static ByteRangeCapturingInputStream getEncryptedInputStream(UploadPartRequest request, CipherFactory cipherFactory) {
    try {
        InputStream originalInputStream = request.getInputStream();
        if (request.getFile() != null) {
            originalInputStream = new InputSubstream(new RepeatableFileInputStream(request.getFile()), request.getFileOffset(), request.getPartSize(), request.isLastPart());
        }
        originalInputStream = new RepeatableCipherInputStream(originalInputStream, cipherFactory);
        if (!request.isLastPart()) {
            // We want to prevent the final padding from being sent on the
            // stream...
            originalInputStream = new InputSubstream(originalInputStream, 0, request.getPartSize(), false);
        }
        long partSize = request.getPartSize();
        int cipherBlockSize = cipherFactory.createCipher().getBlockSize();
        return new ByteRangeCapturingInputStream(originalInputStream, partSize - cipherBlockSize, partSize);
    } catch (Exception e) {
        throw new AmazonClientException("Unable to create cipher input stream: " + e.getMessage(), e);
    }
}
Also used : RepeatableCipherInputStream(com.amazonaws.services.s3.internal.RepeatableCipherInputStream) InputSubstream(com.amazonaws.services.s3.internal.InputSubstream) LengthCheckInputStream(com.amazonaws.util.LengthCheckInputStream) RepeatableFileInputStream(com.amazonaws.services.s3.internal.RepeatableFileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) RepeatableCipherInputStream(com.amazonaws.services.s3.internal.RepeatableCipherInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) AmazonClientException(com.amazonaws.AmazonClientException) RepeatableFileInputStream(com.amazonaws.services.s3.internal.RepeatableFileInputStream) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AmazonClientException(com.amazonaws.AmazonClientException)

Aggregations

RepeatableCipherInputStream (com.amazonaws.services.s3.internal.RepeatableCipherInputStream)2 RepeatableFileInputStream (com.amazonaws.services.s3.internal.RepeatableFileInputStream)2 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)2 LengthCheckInputStream (com.amazonaws.util.LengthCheckInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 AmazonClientException (com.amazonaws.AmazonClientException)1 InputSubstream (com.amazonaws.services.s3.internal.InputSubstream)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1