paddle_model_encrypt.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <iostream>
  16. #include <string>
  17. #include "model_deploy/common/include/deploy_declare.h"
  18. #ifndef PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H
  19. #define PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * generate random key
  25. * 产生随机的 key 信息,如果想要使用当前 SDK,
  26. * 对于传入的key信息有要求(需符合产生32字节随机值后做 BASE64 编码
  27. * @return
  28. */
  29. PD_INFER_DECL std::string paddle_generate_random_key();
  30. /**
  31. * encrypt __model__, __params__ files in src_dir to dst_dir
  32. * @param keydata
  33. * @param src_dir
  34. * @param dst_dir
  35. * @return
  36. */
  37. PD_INFER_DECL int paddle_encrypt_dir(const char* keydata,
  38. const char* src_dir,
  39. const char* dst_dir);
  40. /**
  41. * encrypt file
  42. * @param keydata 可使用由 paddle_generate_random_key 接口产生的key,也可以根据规则自己生成
  43. * @param infile
  44. * @param outfile
  45. * @return error_code
  46. */
  47. PD_INFER_DECL int paddle_encrypt_model(const char* keydata,
  48. const char* infile,
  49. const char* outfile);
  50. PD_INFER_DECL int encrypt_stream(const std::string &keydata,
  51. std::istream &in_stream,
  52. std::ostream &out_stream);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif // PADDLE_MODEL_PROTECT_API_PADDLE_MODEL_ENCRYPT_H