put-encrypted-object.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // +build ignore
  2. /*
  3. * Minio Go Library for Amazon S3 Compatible Cloud Storage
  4. * Copyright 2015-2017 Minio, Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package main
  19. import (
  20. "log"
  21. "os"
  22. "github.com/minio/minio-go"
  23. "github.com/minio/minio-go/pkg/encrypt"
  24. )
  25. func main() {
  26. // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
  27. // my-objectname are dummy values, please replace them with original values.
  28. // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
  29. // This boolean value is the last argument for New().
  30. // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
  31. // determined based on the Endpoint value.
  32. s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
  33. if err != nil {
  34. log.Fatalln(err)
  35. }
  36. // Open a local file that we will upload
  37. file, err := os.Open("my-testfile")
  38. if err != nil {
  39. log.Fatalln(err)
  40. }
  41. defer file.Close()
  42. //// Build an asymmetric key from private and public files
  43. //
  44. // privateKey, err := ioutil.ReadFile("private.key")
  45. // if err != nil {
  46. // t.Fatal(err)
  47. // }
  48. //
  49. // publicKey, err := ioutil.ReadFile("public.key")
  50. // if err != nil {
  51. // t.Fatal(err)
  52. // }
  53. //
  54. // asymmetricKey, err := NewAsymmetricKey(privateKey, publicKey)
  55. // if err != nil {
  56. // t.Fatal(err)
  57. // }
  58. ////
  59. // Build a symmetric key
  60. symmetricKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00"))
  61. // Build encryption materials which will encrypt uploaded data
  62. cbcMaterials, err := encrypt.NewCBCSecureMaterials(symmetricKey)
  63. if err != nil {
  64. log.Fatalln(err)
  65. }
  66. // Encrypt file content and upload to the server
  67. n, err := s3Client.PutEncryptedObject("my-bucketname", "my-objectname", file, cbcMaterials)
  68. if err != nil {
  69. log.Fatalln(err)
  70. }
  71. log.Println("Uploaded", "my-objectname", " of size: ", n, "Successfully.")
  72. }