use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class COSCryptoModuleBase method createInstructionPutRequest.
protected final PutObjectRequest createInstructionPutRequest(String bucketName, String key, ContentCryptoMaterial cekMaterial) {
byte[] bytes = cekMaterial.toJsonString().getBytes(UTF8);
InputStream is = new ByteArrayInputStream(bytes);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(bytes.length);
metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, "");
InstructionFileId ifileId = new COSObjectId(bucketName, key).instructionFileId();
return new PutObjectRequest(ifileId.getBucket(), ifileId.getKey(), is, metadata);
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class COSCryptoModuleBase method initiateMultipartUploadSecurely.
@Override
public InitiateMultipartUploadResult initiateMultipartUploadSecurely(InitiateMultipartUploadRequest req) {
// Generate a one-time use symmetric key and initialize a cipher to
// encrypt object data
ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req);
if (cryptoConfig.getStorageMode() == ObjectMetadata) {
ObjectMetadata metadata = req.getObjectMetadata();
if (metadata == null)
metadata = new ObjectMetadata();
long dataSize = req.getDataSize();
long partSize = req.getPartSize();
if (dataSize < 0 || partSize < 0) {
throw new CosClientException("initiate multipart upload with encryption client must set dataSize and partSize");
}
if (partSize % 16 != 0) {
throw new CosClientException("initiat multipart uplaod with encryption client must set part size a mutiple of 16" + "but got " + partSize);
}
metadata.addUserMetadata(Headers.ENCRYPTION_DATA_SIZE, Long.toString(dataSize));
metadata.addUserMetadata(Headers.ENCRYPTION_PART_SIZE, Long.toString(partSize));
// Store encryption info in metadata
req.setObjectMetadata(updateMetadataWithContentCryptoMaterial(metadata, null, cekMaterial));
}
InitiateMultipartUploadResult result = cos.initiateMultipartUpload(req);
MultipartUploadCryptoContext uploadContext = newUploadContext(req, cekMaterial);
if (req instanceof MaterialsDescriptionProvider) {
MaterialsDescriptionProvider p = (MaterialsDescriptionProvider) req;
uploadContext.setMaterialsDescription(p.getMaterialsDescription());
}
multipartUploadContexts.put(result.getUploadId(), uploadContext);
return result;
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class COSObjectWrapper method hasEncryptionInfo.
/**
* Returns true if this COS object has the encryption information stored as user meta data; false
* otherwise.
*/
final boolean hasEncryptionInfo() {
ObjectMetadata metadata = cosobj.getObjectMetadata();
Map<String, String> userMeta = metadata.getUserMetadata();
return userMeta != null && (userMeta.containsKey(Headers.CRYPTO_IV) || userMeta.containsKey(Headers.ENCRYPTION_START)) && (userMeta.containsKey(Headers.CRYPTO_KEY_V2) || userMeta.containsKey(Headers.CRYPTO_KEY)) || userMeta.containsKey(Headers.ENCRYPTION_KEY);
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class COSObjectWrapper method encryptionSchemeOf.
/**
* Returns the original crypto scheme used for encryption, which may differ from the crypto
* scheme used for decryption during, for example, a range-get operation.
*
* @param instructionFile the instruction file of the cos object; or null if there is none.
*/
ContentCryptoScheme encryptionSchemeOf(Map<String, String> instructionFile) {
if (instructionFile != null) {
String cekAlgo = instructionFile.get(Headers.CRYPTO_CEK_ALGORITHM);
return ContentCryptoScheme.fromCEKAlgo(cekAlgo);
}
ObjectMetadata meta = cosobj.getObjectMetadata();
Map<String, String> userMeta = meta.getUserMetadata();
String cekAlgo = userMeta.get(Headers.CRYPTO_CEK_ALGORITHM);
return ContentCryptoScheme.fromCEKAlgo(cekAlgo);
}
use of com.qcloud.cos.model.ObjectMetadata in project cos-java-sdk-v5 by tencentyun.
the class COSCryptoModuleBase method updateInstructionPutRequest.
/**
* Updates put request to store the specified instruction object in COS.
*
* @param req The put-instruction-file request for the instruction file to be stored in COS.
* @param cekMaterial The instruction object to be stored in COS.
* @return A put request to store the specified instruction object in COS.
*/
protected final PutObjectRequest updateInstructionPutRequest(PutObjectRequest req, ContentCryptoMaterial cekMaterial) {
byte[] bytes = cekMaterial.toJsonString().getBytes(UTF8);
ObjectMetadata metadata = req.getMetadata();
if (metadata == null) {
metadata = new ObjectMetadata();
req.setMetadata(metadata);
}
// Set the content-length of the upload
metadata.setContentLength(bytes.length);
// Set the crypto instruction file header
metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, "");
// Update the instruction request
req.setMetadata(metadata);
req.setInputStream(new ByteArrayInputStream(bytes));
// routine
return req;
}
Aggregations