EncryptionMaterials.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <alibabacloud/oss/encryption/ContentCryptoMaterial.h>
  18. #include <map>
  19. #include <string>
  20. namespace AlibabaCloud
  21. {
  22. namespace OSS
  23. {
  24. class ALIBABACLOUD_OSS_EXPORT EncryptionMaterials
  25. {
  26. public:
  27. virtual ~EncryptionMaterials();
  28. virtual int EncryptCEK(ContentCryptoMaterial& contentCryptoMaterial) = 0;
  29. virtual int DecryptCEK(ContentCryptoMaterial& contentCryptoMaterial) = 0;
  30. };
  31. using RSAEncryptionMaterial = std::pair<std::pair<std::string, std::string>, std::map<std::string, std::string>>;
  32. class ALIBABACLOUD_OSS_EXPORT SimpleRSAEncryptionMaterials : public EncryptionMaterials
  33. {
  34. public:
  35. SimpleRSAEncryptionMaterials(const std::string& publicKey, const std::string& privateKey);
  36. SimpleRSAEncryptionMaterials(const std::string& publicKey, const std::string& privateKey,
  37. const std::map<std::string, std::string>& description);
  38. ~SimpleRSAEncryptionMaterials();
  39. void addEncryptionMaterial(const std::string& publicKey, const std::string& privateKey,
  40. const std::map<std::string, std::string>& description);
  41. virtual int EncryptCEK(ContentCryptoMaterial& contentCryptoMaterial);
  42. virtual int DecryptCEK(ContentCryptoMaterial& contentCryptoMaterial);
  43. private:
  44. int findIndexByDescription(const std::map<std::string, std::string>& description);
  45. std::string publicKey_;
  46. std::map<std::string, std::string> description_;
  47. std::vector<RSAEncryptionMaterial> encryptionMaterials_;
  48. };
  49. }
  50. }