本文整理汇总了C++中fromHex函数的典型用法代码示例。如果您正苦于以下问题:C++ fromHex函数的具体用法?C++ fromHex怎么用?C++ fromHex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromHex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parsePercentEncoding
static QByteArray parsePercentEncoding(const QByteArray &in)
{
QByteArray out;
for(int n = 0; n < in.size(); ++n)
{
char c = in[n];
if(c == '%')
{
if(n + 2 >= in.size())
return QByteArray();
int hi = fromHex(in[n + 1]);
if(hi == -1)
return QByteArray();
int lo = fromHex(in[n + 2]);
if(lo == -1)
return QByteArray();
unsigned char val = (hi << 4) + lo;
out += val;
n += 2; // adjust position
}
else
out += c;
}
return out;
}
示例2: GetCBOREncoding
byte * GetCBOREncoding(const cn_cbor * pControl, int * pcbEncoded)
{
const cn_cbor * pOutputs = cn_cbor_mapget_string(pControl, "output");
const cn_cbor * pCBOR;
byte * pb = NULL;
const byte * pb2;
int i;
if ((pOutputs == NULL) || (pOutputs->type != CN_CBOR_MAP)) {
fprintf(stderr, "Invalid output\n");
exit(1);
}
pCBOR = cn_cbor_mapget_string(pOutputs, "cbor");
if ((pCBOR == NULL) || (pCBOR->type != CN_CBOR_TEXT)) {
fprintf(stderr, "Invalid cbor object");
exit(1);
}
pb = malloc(pCBOR->length / 2);
pb2 = pCBOR->v.bytes;
for (i = 0; i < pCBOR->length; i += 2) {
pb[i / 2] = fromHex(pb2[i]) * 16 + fromHex(pb2[i + 1]);
}
*pcbEncoded = (int) (pCBOR->length / 2);
return pb;
}
示例3: if
std::string CEncrypt::urlDecode(std::string strVal)
{
const char *pszVal = strVal.c_str();
std::string strTemp = "";
size_t iLens = strVal.size();
for (size_t i = 0; i < iLens; i++)
{
if ('+' == pszVal[i])
{
strTemp += ' ';
}
else if ('%' == pszVal[i])
{
assert(i + 2 < iLens);
unsigned char cHigh = fromHex((unsigned char)pszVal[++i]);
unsigned char cLow = fromHex((unsigned char)pszVal[++i]);
strTemp += cHigh*16 + cLow;
}
else
{
strTemp += pszVal[i];
}
}
return strTemp;
}
示例4: check
static bool check(
bool ok,
const uint8_t *rmdHex,
const uint8_t *dataHex
) {
uint8_t rmd[kRIPEMD160ByteSize];
fromHex(rmd, rmdHex, kRIPEMD160ByteSize, false);
uint8_t data[1024];
auto dataLen = strlen((const char*)dataHex)/2;
if(0<dataLen) {
fromHex(data, dataHex, dataLen, false);
}
uint8_t cmp[kRIPEMD160ByteSize];
rmd160(cmp, data, dataLen);
TEST_CHECK(
ok,
0==memcmp(cmp, rmd, sizeof(rmd)),
"RIPEMD-160 fails for %s\n",
dataHex
);
return ok;
}
示例5: readVector
static void readVector(char * pszVec,
unsigned int cbVec, octet * pabVec)
{
unsigned int i = cbVec;
memset(pabVec, 0, cbVec);
for ( ; i && pszVec[0] && pszVec[1]; pszVec += 2, pabVec++, i--) {
*pabVec = (fromHex(pszVec[0]) << 4) | fromHex(pszVec[1]);
}
if (!i && *pszVec) printUsage(1);
}
示例6: fromHex
bool Color::fromString(const string &str)
{
if(str.length() != 4 && str.length() != 7)
return false;
if(str[0] != '#') return false;
for(string::size_type i = 1; i < str.length(); ++i) {
if(!isxdigit((int)str[i]))
return false;
}
if(str.length() == 7) {
m_red = (__uint8)( (fromHex(str[1]) << 4) + fromHex(str[2]) );
m_green = (__uint8)( (fromHex(str[3]) << 4) + fromHex(str[4]) );
m_blue = (__uint8)( (fromHex(str[5]) << 4) + fromHex(str[6]) );
} else {
__uint8 v = fromHex(str[1]);
m_red = (__uint8)( (v << 4) + v );
v = fromHex(str[2]);
m_green = (__uint8)( (v << 4) + v );
v = fromHex(str[3]);
m_blue = (__uint8)( (v << 4) + v );
}
m_alpha = 255;
return true;
}
示例7: FromHex
byte * FromHex(const char * rgch, int cch)
{
byte * pb = malloc(cch / 2);
const char * pb2 = rgch;
int i;
for (i = 0; i < cch; i += 2) {
pb[i / 2] = fromHex(pb2[i]) * 16 + fromHex(pb2[i + 1]);
}
return pb;
}
示例8: hex_decode
Bytes hex_decode(const String& string)
{
Bytes ret;
ret.reserve(string.length()/2);
for (auto i: range(0, (string.length()/2)*2, 2))
{
if (!isHex(string[i]) || !isHex(string[i+1])) break;
ret.push_back((fromHex(string[i]) << 4) | fromHex(string[i+1]));
}
return ret;
}
示例9: THROW
Derived Id<n, Derived>::FromString(const String& string)
{
if(string.length() != n * 2)
THROW(String("Wrong length of id string for ") + typeid(Derived).name());
Derived id;
for(int i = 0; i < n; ++i)
id.data[i] = (fromHex(string[i * 2]) << 4) | fromHex(string[i * 2 + 1]);
return id;
}
示例10: crypt
bool WPUtils::crypt(bool isEncrypt, const QByteArray & in,
QByteArray & out) {
QByteArray key, iv;
QString fail;
if (!fromHex(_key, key)) {
fail += "Key is not valid hex. ";
}
if (!fromHex(_iv, iv)) {
fail += "IV is not valid hex. ";
}
if (!fail.isEmpty()) {
qDebug() << "fail = " << fail;
//toast(fail);
return false;
}
AESParams params(globalContext);
if (!params.isValid()) {
//toast(
qDebug () << "fails = " << QString("Could not create params. %1").arg(SBError::getErrorText(params.lastError()));
return false;
}
AESKey aesKey(params, key);
if (!aesKey.isValid()) {
qDebug() << "failes = " << QString("Could not create a key. %1").arg(SBError::getErrorText(aesKey.lastError()));
return false;
}
int rc;
if (isEncrypt) {
rc = hu_AESEncryptMsg(params.aesParams(), aesKey.aesKey(), iv.length(),
(const unsigned char*) iv.constData(), in.length(),
(const unsigned char *) in.constData(),
(unsigned char *) out.data(), globalContext.ctx());
} else {
rc = hu_AESDecryptMsg(params.aesParams(), aesKey.aesKey(), iv.length(),
(const unsigned char*) iv.constData(), in.length(),
(const unsigned char *) in.constData(),
(unsigned char *) out.data(), globalContext.ctx());
}
if (rc == SB_SUCCESS) {
return true;
}
//toast
qDebug() << QString("Crypto operation failed. %1").arg(SBError::getErrorText(rc));
return false;
}
示例11: convertColorFromString
QColor convertColorFromString(const QString &s)
{
if (s.length() == 9 && s.startsWith(QLatin1Char('#'))) {
uchar a = fromHex(s, 1);
uchar r = fromHex(s, 3);
uchar g = fromHex(s, 5);
uchar b = fromHex(s, 7);
return QColor(r, g, b, a);
} else {
QColor rv(s);
return rv;
}
}
示例12: fromHex
QColor QDeclarativeStringConverters::colorFromString(const QString &s, bool *ok)
{
if (s.length() == 9 && s.startsWith(QLatin1Char('#'))) {
uchar a = fromHex(s, 1);
uchar r = fromHex(s, 3);
uchar g = fromHex(s, 5);
uchar b = fromHex(s, 7);
if (ok) *ok = true;
return QColor(r, g, b, a);
} else {
QColor rv(s);
if (ok) *ok = rv.isValid();
return rv;
}
}
示例13: ReadPrefHex
uint32_t ReadPrefHex(const char* pref_key)
{
LoadConfigFile();
std::string pref = "preferences:";
pref.append(pref_key);
return fromHex(iniparser_getstring(preferences, pref.c_str(), 0));
}
示例14: cipher
void CiscoSecret7::transform(const QByteArray &input, QByteArray &output)
{
if (wayValue == INBOUND) {
QByteArray data;
cipher(seed,input, data);
output = data.toHex().prepend(QByteArray::number(seed));
} else {
QByteArray encrypted = input.toUpper();
if (encrypted.isEmpty())
return;
if (encrypted.size() < 3) {
emit error(tr("Invalid hash (far too small)"),id);
return;
}
bool k = true;
seed = encrypted.mid(0,2).toInt(&k);
if (!k || seed > MAXSEED) {
emit error(tr("Invalid seed, it must be an unsigned integer <= %1").arg(MAXSEED),id);
return;
}
QByteArray data = encrypted.mid(2);
data = fromHex(data);
cipher(seed,data,output);
}
}
示例15: testAddr2Hash
static bool testAddr2Hash(
const uint8_t *addr,
const uint8_t *hexHash
) {
uint8_t result[kRIPEMD160ByteSize];
auto ok = addrToHash160(result, addr, true);
TEST_CHECK(ok, ok, "failed to decode address %s", addr);
uint8_t hash[kRIPEMD160ByteSize];
fromHex(hash, (const uint8_t*)hexHash, kRIPEMD160ByteSize, false);
uint8_t hexResult[1 + 2*kRIPEMD160ByteSize];
toHex(hexResult, result, kRIPEMD160ByteSize, false);
TEST_CHECK(
ok,
0==memcmp(result, hash, kRIPEMD160ByteSize),
"decode fail\n"
" for addr: %s\n"
" expected: %s\n"
" got: %s\n"
"\n",
addr,
hexHash,
hexResult
);
return ok;
}