简体   繁体   English

如何将'const char *'转换为'const unsigned char *'

[英]how to convert 'const char *' to 'const unsigned char *'

how to convert 'const char *' to 'const unsigned char *' 如何将'const char *'转换为'const unsigned char *'

 bool AES(const uint8_t *Data, size_t Size) {  
     std::string s(reinterpret_cast<const char *>(Data), Size);
     AES_cbc_encrypt(s.c_str(), enc_out, Size, &enc_key, iv, AES_ENCRYPT);
    }

the error got while compilation of the program 程序编译时出现错误

candidate function not viable: no known conversion from 'const char *' to 'const unsigned char *'
      for 1st argument
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,

I tried this doesn't work 我试过这不起作用

std::string s(reinterpret_cast<const unsigned char *>(Data), Size);

uint8_t , if it's available , is just a typedef to unsigned char . uint8_t如果可用 )只是unsigned char的typedef。 Therefore, you can just do: 因此,您可以执行以下操作:

 bool AES(const uint8_t *Data, size_t Size) {  
     AES_cbc_encrypt(Data, enc_out, Size, &enc_key, iv, AES_ENCRYPT);
 }

Note that you should probably return something in your function as well. 注意,您可能还应该在函数中返回某些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM