public void PutObjectWithCustomerKey(COSXML.CosXml cosXml, string bucket, string key, string srcPath) { try { PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); request.IsHttps = true; //设置进度回调 request.SetCosProgressCallback(delegate(long completed, long total) { //Console.WriteLine(String.Format("{0} progress = {1} / {2} : {3:##.##}%", DateTime.Now.ToString(), completed, total, completed * 100.0 / total)); }); string customerKey = "25rN73uQtl1bUGnvHe0URgFWBNu4vBba";//32字符 request.SetCosServerSideEncryptionWithCustomerKey(customerKey); //执行请求 PutObjectResult result = cosXml.PutObject(request); Console.WriteLine(result.GetResultInfo()); } catch (CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.True(false); } catch (CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.True(false); } }
public void PutObjectWithCustomerKey() { try { string key = "objectWithSSEC"; PutObjectRequest request = new PutObjectRequest(bucket, key, smallFileSrcPath); string customerKey = "25rN73uQtl1bUGnvHe0URgFWBNu4vBba";//32字符 request.SetCosServerSideEncryptionWithCustomerKey(customerKey); //执行请求 PutObjectResult result = cosXml.PutObject(request); Console.WriteLine(result.GetResultInfo()); } catch (CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.True(false); } catch (CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.True(false); } }
/// 使用客户提供的加密密钥的服务端加密 (SSE-C)保护数据 public void PutObjectSseC() { string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID string key = "exampleobject"; //对象键 string srcPath = @"temp-source-file"; //本地文件绝对路径 //.cssg-snippet-body-start:[put-object-sse-c] PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath); request.SetCosServerSideEncryptionWithCustomerKey("Your Secret Key"); //.cssg-snippet-body-end }