paddle_safe_stream_test.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2020 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. #include <iostream>
  15. #include <string>
  16. #include <sstream>
  17. #include "encryption/include/paddle_model_encrypt.h"
  18. #include "encryption/include/paddle_stream_decrypt.h"
  19. int main() {
  20. std::string key_data = paddle_generate_random_key();
  21. std::cout << "key is:" << key_data << std::endl;
  22. std::istringstream isst(std::string("hello world !"));
  23. std::ostringstream osst;
  24. int enc_ret = encrypt_stream(key_data, isst, osst);
  25. if (enc_ret != 0) {
  26. std::cout << "ERROR paddle_encrypt_stream" << enc_ret <<std::endl;
  27. return 0;
  28. }
  29. std::istringstream isst_cipher(osst.str());
  30. std::ostringstream osst_plain;
  31. int dec_ret = decrypt_stream(isst_cipher, osst_plain, key_data);
  32. if (dec_ret != 0) {
  33. std::cout << "ERROR decrypt_stream " << dec_ret <<std::endl;
  34. return 0;
  35. }
  36. std::cout << "data is:" << osst_plain.str() << std::endl;
  37. return 0;
  38. }