You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

crypto_pybind.cc 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  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. #include "crypto/crypto_pybind.h"
  17. namespace mindspore {
  18. namespace crypto {
  19. py::bytes PyEncrypt(char *plain_data, const int64_t plain_len, char *key, const int32_t key_len, std::string enc_mode) {
  20. int64_t encrypt_len;
  21. char *encrypt_data;
  22. encrypt_data = reinterpret_cast<char *>(Encrypt(&encrypt_len, reinterpret_cast<Byte *>(plain_data), plain_len,
  23. reinterpret_cast<Byte *>(key), key_len, enc_mode));
  24. return py::bytes(encrypt_data, encrypt_len);
  25. }
  26. py::bytes PyDecrypt(std::string encrypt_data_path, char *key, const int32_t key_len, std::string dec_mode) {
  27. int64_t decrypt_len;
  28. char *decrypt_data;
  29. decrypt_data = reinterpret_cast<char *>(
  30. Decrypt(&decrypt_len, encrypt_data_path, reinterpret_cast<Byte *>(key), key_len, dec_mode));
  31. return py::bytes(decrypt_data, decrypt_len);
  32. }
  33. bool PyIsCipherFile(std::string file_path) { return IsCipherFile(file_path); }
  34. } // namespace crypto
  35. } // namespace mindspore