public class EncryptionUtils extends Object
Constructor and Description |
---|
EncryptionUtils() |
Modifier and Type | Method and Description |
---|---|
static S3Object |
adjustOutputToDesiredRange(S3Object object,
long[] range)
Adjusts the retrieved S3Object so that the object contents contain only the range of bytes
desired by the user.
|
static EncryptionInstruction |
buildInstructionFromInstructionFile(S3Object instructionFile,
EncryptionMaterials materials,
Provider cryptoProvider)
Deprecated.
|
static EncryptionInstruction |
buildInstructionFromInstructionFile(S3Object instructionFile,
EncryptionMaterialsProvider materialsProvider,
Provider cryptoProvider)
Builds an instruction object from the contents of an instruction file.
|
static EncryptionInstruction |
buildInstructionFromObjectMetadata(S3Object object,
EncryptionMaterials materials,
Provider cryptoProvider)
Deprecated.
|
static EncryptionInstruction |
buildInstructionFromObjectMetadata(S3Object object,
EncryptionMaterialsProvider materialsProvider,
Provider cryptoProvider)
Builds an instruction object from the object metadata.
|
static long |
calculateCryptoContentLength(Cipher symmetricCipher,
UploadPartRequest request) |
static DeleteObjectRequest |
createInstructionDeleteObjectRequest(DeleteObjectRequest request)
Creates a delete request to delete an instruction file in S3.
|
static GetObjectRequest |
createInstructionGetRequest(GetObjectRequest request)
Creates a get request to retrieve an instruction file from S3.
|
static PutObjectRequest |
createInstructionPutRequest(PutObjectRequest request,
EncryptionInstruction instruction)
Creates a put request to store the specified instruction object in S3.
|
static PutObjectRequest |
createInstructionPutRequest(String bucketName,
String key,
EncryptionInstruction instruction) |
static Cipher |
createSymmetricCipher(SecretKey symmetricCryptoKey,
int encryptMode,
Provider cryptoProvider,
byte[] initVector)
Creates a symmetric cipher in the specified mode from the given symmetric key and IV.
|
static S3Object |
decryptObjectUsingInstruction(S3Object object,
EncryptionInstruction instruction)
Returns an updated object where the object content input stream contains the decrypted contents.
|
static S3Object |
decryptObjectUsingMetadata(S3Object object,
EncryptionMaterials materials,
Provider cryptoProvider)
Deprecated.
use buildInstructionFromObjectMetadata and decryptObjectUsingInstruction instead.
|
static PutObjectRequest |
encryptRequestUsingInstruction(PutObjectRequest request,
EncryptionInstruction instruction)
Returns an updated request where the input stream contains the encrypted object contents.
|
static PutObjectRequest |
encryptRequestUsingMetadata(PutObjectRequest request,
EncryptionMaterials materials,
Provider cryptoProvider)
Deprecated.
use generateInstruction, encryptRequestUsingInstruction, and updateMetadataWithEncryptionInfo instead
|
static EncryptionInstruction |
generateInstruction(EncryptionMaterials materials,
Provider cryptoProvider)
Deprecated.
|
static EncryptionInstruction |
generateInstruction(EncryptionMaterialsProvider materialsProvider,
Provider cryptoProvider) |
static SecretKey |
generateOneTimeUseSymmetricKey()
Generates a one-time use Symmetric Key on-the-fly for use in envelope encryption.
|
static long[] |
getAdjustedCryptoRange(long[] range)
Adjusts a user specified range to retrieve all of the cipher blocks (each of size 16 bytes) that
contain the specified range.
|
static ByteRangeCapturingInputStream |
getEncryptedInputStream(UploadPartRequest request,
CipherFactory cipherFactory) |
static byte[] |
getEncryptedSymmetricKey(SecretKey toBeEncrypted,
EncryptionMaterials materials,
Provider cryptoProvider)
Encrypts a symmetric key using the provided encryption materials and returns
it in raw byte array form.
|
static boolean |
isEncryptionInfoInInstructionFile(S3Object instructionFile)
Returns true if the specified S3Object is an instruction file containing
encryption info, false otherwise.
|
static boolean |
isEncryptionInfoInMetadata(S3Object retrievedObject)
Returns true if the specified S3Object contains encryption info in its
metadata, false otherwise.
|
static ObjectMetadata |
updateMetadataWithEncryptionInfo(InitiateMultipartUploadRequest request,
byte[] keyBytesToStoreInMetadata,
Cipher symmetricCipher,
Map<String,String> materialsDescription) |
static void |
updateMetadataWithEncryptionInstruction(PutObjectRequest request,
EncryptionInstruction instruction)
Update the request's ObjectMetadata with the necessary information for decrypting the object
|
@Deprecated public static PutObjectRequest encryptRequestUsingMetadata(PutObjectRequest request, EncryptionMaterials materials, Provider cryptoProvider)
request
- The request whose contents are to be encrypted.materials
- The encryption materials to be used to encrypt and decrypt data.cryptoProvider
- The crypto provider whose encryption implementation will be used to encrypt data@Deprecated public static S3Object decryptObjectUsingMetadata(S3Object object, EncryptionMaterials materials, Provider cryptoProvider)
object
- The object whose contents are to be decrypted.materials
- The encryption materials to be used to encrypt and decrypt data.cryptoProvider
- The crypto provider whose encryption implementation will be used to decrypt data@Deprecated public static EncryptionInstruction generateInstruction(EncryptionMaterials materials, Provider cryptoProvider)
materials
- The encryption materials to be used to encrypt and decrypt data.cryptoProvider
- The crypto provider whose encryption implementation will be used to encrypt and decrypt data.public static EncryptionInstruction generateInstruction(EncryptionMaterialsProvider materialsProvider, Provider cryptoProvider)
@Deprecated public static EncryptionInstruction buildInstructionFromInstructionFile(S3Object instructionFile, EncryptionMaterials materials, Provider cryptoProvider)
instructionFile
- A non-null instruction file retrieved from S3 that contains encryption informationmaterials
- The non-null encryption materials to be used to encrypt and decrypt data.cryptoProvider
- The crypto provider whose encryption implementation will be used to encrypt and decrypt data. Null is ok and uses the
preferred provider from Security.getProviders().public static EncryptionInstruction buildInstructionFromInstructionFile(S3Object instructionFile, EncryptionMaterialsProvider materialsProvider, Provider cryptoProvider)
instructionFile
- A non-null instruction file retrieved from S3 that contains encryption informationmaterialsProvider
- The non-null encryption materials provider to be used to encrypt and decrypt data.cryptoProvider
- The crypto provider whose encryption implementation will be used to encrypt and decrypt data. Null is ok and uses the
preferred provider from Security.getProviders().@Deprecated public static EncryptionInstruction buildInstructionFromObjectMetadata(S3Object object, EncryptionMaterials materials, Provider cryptoProvider)
object
- A non-null object that contains encryption information in its headersmaterials
- The non-null encryption materials to be used to encrypt and decrypt data.cryptoProvider
- The crypto provider whose encryption implementation will be used to encrypt and decrypt data. Null is ok and uses the
preferred provider from Security.getProviders().AmazonClientException
- if encryption information is missing in the metadata, or the encryption
materials used to encrypt the object are not available via the materials Accessorpublic static EncryptionInstruction buildInstructionFromObjectMetadata(S3Object object, EncryptionMaterialsProvider materialsProvider, Provider cryptoProvider)
object
- A non-null object that contains encryption information in its headersmaterialsProvider
- The non-null encryption materials provider to be used to encrypt and decrypt data.cryptoProvider
- The crypto provider whose encryption implementation will be used to encrypt and decrypt data. Null is ok and uses the
preferred provider from Security.getProviders().AmazonClientException
- if encryption information is missing in the metadata, or the encryption
materials used to encrypt the object are not available via the materials Accessorpublic static PutObjectRequest encryptRequestUsingInstruction(PutObjectRequest request, EncryptionInstruction instruction)
request
- The request whose contents are to be encrypted.instruction
- The instruction that will be used to encrypt the object data.public static S3Object decryptObjectUsingInstruction(S3Object object, EncryptionInstruction instruction)
object
- The object whose contents are to be decrypted.instruction
- The instruction that will be used to decrypt the object data.public static PutObjectRequest createInstructionPutRequest(PutObjectRequest request, EncryptionInstruction instruction)
request
- The put request for the original object to be stored in S3.instruction
- The instruction object to be stored in S3.public static PutObjectRequest createInstructionPutRequest(String bucketName, String key, EncryptionInstruction instruction)
public static GetObjectRequest createInstructionGetRequest(GetObjectRequest request)
request
- The get request for the original object to be retrieved from S3.public static DeleteObjectRequest createInstructionDeleteObjectRequest(DeleteObjectRequest request)
request
- The delete request for the original object to be deleted from S3.public static boolean isEncryptionInfoInMetadata(S3Object retrievedObject)
retrievedObject
- An S3Objectpublic static boolean isEncryptionInfoInInstructionFile(S3Object instructionFile)
instructionFile
- An S3Object that may potentially be an instruction filepublic static long[] getAdjustedCryptoRange(long[] range)
range
- A two-element array of longs corresponding to the start and finish (inclusive) of a desired
range of bytes.public static S3Object adjustOutputToDesiredRange(S3Object object, long[] range)
object
- The S3Object retrieved from S3 that could possibly contain more bytes than desired
by the user.range
- A two-element array of longs corresponding to the start and finish (inclusive) of a desired
range of bytes.public static SecretKey generateOneTimeUseSymmetricKey()
public static Cipher createSymmetricCipher(SecretKey symmetricCryptoKey, int encryptMode, Provider cryptoProvider, byte[] initVector)
public static byte[] getEncryptedSymmetricKey(SecretKey toBeEncrypted, EncryptionMaterials materials, Provider cryptoProvider)
public static ByteRangeCapturingInputStream getEncryptedInputStream(UploadPartRequest request, CipherFactory cipherFactory)
public static void updateMetadataWithEncryptionInstruction(PutObjectRequest request, EncryptionInstruction instruction)
request
- Non-null PUT request encrypted using the given instructioninstruction
- Non-null instruction used to encrypt the data in this PUT request.public static ObjectMetadata updateMetadataWithEncryptionInfo(InitiateMultipartUploadRequest request, byte[] keyBytesToStoreInMetadata, Cipher symmetricCipher, Map<String,String> materialsDescription)
public static long calculateCryptoContentLength(Cipher symmetricCipher, UploadPartRequest request)
Copyright © 2016. All rights reserved.