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

时间:2017-02-17 16:43:57

标签: c++ aes

如何将'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);
    }

编译程序时出错

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,

我试过这不起作用

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

1 个答案:

答案 0 :(得分:1)

uint8_tif it's available,只是unsigned char的typedef。因此,您可以这样做:

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

请注意,您也应该在函数中返回一些内容。