paddle_safe_stream_test.cpp 895 B

123456789101112131415161718192021222324252627282930313233
  1. #include "../include/paddle_model_encrypt.h"
  2. #include "../include/paddle_stream_decrypt.h"
  3. #include <iostream>
  4. #include <string>
  5. #include <sstream>
  6. int main(){
  7. std::string key_data = paddle_generate_random_key();
  8. std::cout << "key is:" << key_data << std::endl;
  9. std::istringstream isst(std::string("hello world !"));
  10. std::ostringstream osst;
  11. int enc_ret = encrypt_stream(key_data, isst, osst);
  12. if (enc_ret != 0){
  13. std::cout << "ERROR paddle_encrypt_stream" << enc_ret <<std::endl;
  14. return 0;
  15. }
  16. std::istringstream isst_cipher(osst.str());
  17. std::ostringstream osst_plain;
  18. int dec_ret = decrypt_stream(isst_cipher, osst_plain, key_data);
  19. if (dec_ret != 0){
  20. std::cout << "ERROR decrypt_stream " << dec_ret <<std::endl;
  21. return 0;
  22. }
  23. std::cout << "data is:" << osst_plain.str() << std::endl;
  24. return 0;
  25. }