Пример #1
0
bool DecodeAddress(string str, CAddress& addr)
{
    vector<unsigned char> vch;
    if (!DecodeBase58Check(str.substr(1), vch))
        return false;

    struct ircaddr tmp;
    if (vch.size() != sizeof(tmp))
        return false;
    memcpy(&tmp, &vch[0], sizeof(tmp));

    addr = CAddress(tmp.ip, ntohs(tmp.port), NODE_NETWORK);
    return true;
}
Пример #2
0
bool CBase58Data::SetString(const char* psz, unsigned int nVersionBytes) {
    std::vector<unsigned char> vchTemp;
    bool rc58 = DecodeBase58Check(psz, vchTemp);
    if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
        vchData.clear();
        vchVersion.clear();
        return false;
    }
    vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
    vchData.resize(vchTemp.size() - nVersionBytes);
    if (!vchData.empty())
        memcpy(&vchData[0], &vchTemp[nVersionBytes], vchData.size());
    OPENSSL_cleanse(&vchTemp[0], vchData.size());
    return true;
}
Пример #3
0
CKey DecodeSecret(const std::string& str)
{
    CKey key;
    std::vector<unsigned char> data;
    if (DecodeBase58Check(str, data)) {
        const std::vector<unsigned char>& privkey_prefix = Params().Base58Prefix(CChainParams::SECRET_KEY);
        if ((data.size() == 32 + privkey_prefix.size() || (data.size() == 33 + privkey_prefix.size() && data.back() == 1)) &&
            std::equal(privkey_prefix.begin(), privkey_prefix.end(), data.begin())) {
            bool compressed = data.size() == 33 + privkey_prefix.size();
            key.Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed);
        }
    }
    memory_cleanse(data.data(), data.size());
    return key;
}
Пример #4
0
 bool CBase58Data::SetString(const char* psz, unsigned int nVersionBytes)
 {
     std::vector<unsigned char> vchTemp;
     bool rc58 = DecodeBase58Check(psz, vchTemp);
     if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
         vchData.clear();
         vchVersion.clear();
         throw InvalidAddressException();
     }
     vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
     vchData.resize(vchTemp.size() - nVersionBytes);
     if (!vchData.empty())
         memcpy(vchData.data(), vchTemp.data() + nVersionBytes, vchData.size());
     return true;
 }
Пример #5
0
bool CryptoUtil::Base58CheckDecode(const String& input, OTData& output)
{
    std::vector<unsigned char> decodedInput;
    bool decoded = DecodeBase58Check(input.Get(), decodedInput);

    if (decoded) {
        OTData dataOutput(decodedInput);
        output = dataOutput;

        return true;
    } else {

        return false;
    }
}
Пример #6
0
 bool CBase58Data::SetString(const char* psz)
 {
     std::vector<unsigned char> vchTemp;
     DecodeBase58Check(psz, vchTemp);
     if (vchTemp.empty())
     {
         vchData.clear();
         nVersion = 0;
         return false;
     }
     nVersion = vchTemp[0];
     vchData.resize(vchTemp.size() - 1);
     if (!vchData.empty())
         memcpy(&vchData[0], &vchTemp[1], vchData.size());
     OPENSSL_cleanse(&vchTemp[0], vchData.size());
     return true;
 }
Пример #7
0
bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet) {
    return DecodeBase58Check(str.c_str(), vchRet);
}
bool DecodeBase58Check(const std::string &str, std::vector<uint8_t> &vchRet) {
    return DecodeBase58Check(str.c_str(), vchRet);
}