Example of Encryption
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
Encrypting an Object to Be Uploaded
Sample code of uploading objects with SSE-C encryption:
For more information, see Server-Side Encryption.
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
PutObjectRequest request = new PutObjectRequest();
request.setBucketName("bucketname");
request.setObjectKey("objectname");
request.setFile(new File("localfile"));
// Set the SSE-C encryption algorithm.
SseCHeader sseCHeader = new SseCHeader();
sseCHeader.setAlgorithm(ServerAlgorithm.AES256);
sseCHeader.setSseCKeyBase64("your base64 sse-c key generated by AES-256 algorithm");
request.setSseCHeader(sseCHeader);
obsClient.putObject(request);
Decrypting a Downloaded Object
Sample code of downloading objects and decrypt the SSE-C encryption:
String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
GetObjectRequest request = new GetObjectRequest("bucketname", "objectname");
// Set the encryption algorithm to SSE-C.
SseCHeader sseCHeader = new SseCHeader();
sseCHeader.setAlgorithm(ServerAlgorithm.AES256);
// The key used here must be the one used for uploading the object.
sseCHeader.setSseCKeyBase64("your base64 sse-c key generated by AES-256 algorithm");
request.setSseCHeader(sseCHeader);
ObsObject obsObject = obsClient.getObject(request);
obsObject.getObjectContent().close();
Last Article: Encryption Description
Next Article: Troubleshooting

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.