将十六进制字符串转换为crypto ++中的字节 [英] Convert Hex string to bytes in crypto++

查看:161
本文介绍了将十六进制字符串转换为crypto ++中的字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个十六进制的字符串,我需要转换为 const byte * 。我正在使用Crypto ++来做哈希,它需要的关键是在 const byte * 有没有办法我可以将十六进制的字符串转换为 const字节* 使用任何Crypto ++库,还是需要我自己的?

解决方案

Crypto ++中有一个 HexDecoder 类。



您需要提供这些字符。似乎Crypto ++不直接区分字符和字节。因此,由varren提供的以下代码行将起作用:

  StringSource ss(source,true,new HexEncoder(new StringSink ))); 
const byte * result =(const byte *)destination.data();


I have string of hexadecimals which I need to convert to const byte*. I am using Crypto++ to do hashing and it needs the key to be in const byte* Is there any way i can convert the string of hexadecimal into const byte* using any of the Crypto++ libs or must i need to come up with my own?

解决方案

There is a HexDecoder class in Crypto++.

You need to feed this characters. It seems that Crypto++ does not directly distinguish between characters and bytes. So the following line of code supplied by varren will work:

StringSource ss(source, true, new HexEncoder(new StringSink(destination)));
const byte* result = (const byte*) destination.data();

这篇关于将十六进制字符串转换为crypto ++中的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆