• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ SHA256类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中SHA256的典型用法代码示例。如果您正苦于以下问题:C++ SHA256类的具体用法?C++ SHA256怎么用?C++ SHA256使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SHA256类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: test_hash

void TestApp::test_hash(const SHA256 &sha256, const char *hash_text)
{
	std::string hash = sha256.get_hash(true);
	if (hash != hash_text)
		fail();

	if (strlen(hash_text) != 64)
		fail();

	unsigned char out_hash[32];
	sha256.get_hash(out_hash);
	for (int cnt=0; cnt<32; cnt++)
	{
		unsigned int value = out_hash[cnt];
		char nibble_high = *(hash_text++);
		char nibble_low = *(hash_text++);

		nibble_high >= 'A' ? (nibble_high = nibble_high - 'A' + 10) : nibble_high = nibble_high - '0';
		nibble_low >= 'A' ? (nibble_low = nibble_low - 'A' + 10) : nibble_low = nibble_low - '0';

		if (value != ((nibble_high << 4) | (nibble_low) ))
			fail();
	}

}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:25,代码来源:test_sha256.cpp


示例2: getMacAddress

QVector<QString> & PBSKeygen::getKeys() {
	SHA256 sha;

	QString macS = getMacAddress();
	if (macS.length() != 12) {
		throw ERROR;
	}

	char mac[6];
	bool status;
	for (int i = 0; i < 12; i += 2)
		mac[i / 2] = (macS.mid(i, 1).toInt(&status, 16) << 4)
				+ macS.mid(i + 1, 1).toInt(&status, 16);
	if (!status)
		throw ERROR;
	sha.reset();
	sha.addData(saltSHA256, (unsigned long)sizeof(saltSHA256));
	sha.addData(mac, (unsigned long)sizeof(mac));

	unsigned char hash[32];
	sha.result((unsigned char *) hash);
	QString key = "";
	for (int i = 0; i < 13; ++i) {
		key.append(lookup.at(hash[i] % lookup.length()));
	}
	results.append(key);
	return results;
}
开发者ID:Bernd1,项目名称:routerkeygen,代码行数:28,代码来源:PBSKeygen.cpp


示例3: lock

      //---------------------------------------------------------------------
      bool PeerContactProfile::usesContactProfileSecret(const char *contactProfileSecret)
      {
        AutoRecursiveLock lock(mLock);
        if (NULL == contactProfileSecret) return false;
        if (!mDocument) return false;

        try {
          ElementPtr contactProfileElement = getContactProfileElement();
          if (!contactProfileElement) return false;
          ElementPtr proofElement = contactProfileElement->findFirstChildElementChecked("private")->findFirstChildElementChecked("proof");
          String proofAsBase64 = proofElement->getText(true);
          SecureByteBlock proofHash;
          convertFromBase64(proofAsBase64, proofHash);

          SecureByteBlock calculatedProofHash(32);
          if (calculatedProofHash.size() != proofHash.size()) return false;

          SHA256 shaProof;
          shaProof.Update((const BYTE *)"proof:", strlen("proof:"));
          shaProof.Update((const BYTE *)contactProfileSecret, strlen(contactProfileSecret));
          shaProof.Final(calculatedProofHash);

          if (0 != memcmp(calculatedProofHash, proofHash, proofHash.size())) return false;

          // this is the secret and it is verified
          mContactProfileSecret = contactProfileSecret;

        } catch (zsLib::XML::Exceptions::CheckFailed &) {
          return false;
        }
        return true;
      }
开发者ID:Gurtej,项目名称:op,代码行数:33,代码来源:stack_PeerContactProfile.cpp


示例4: EncryptPassword

// Non-public secure PBKDF2 hash function with salting and 1,337 iterations
std::string JSI_Lobby::EncryptPassword(const std::string& password, const std::string& username)
{
	const int DIGESTSIZE = SHA_DIGEST_SIZE;
	const int ITERATIONS = 1337;

	static const unsigned char salt_base[DIGESTSIZE] = {
			244, 243, 249, 244, 32, 33, 34, 35, 10, 11, 12, 13, 14, 15, 16, 17,
			18, 19, 20, 32, 33, 244, 224, 127, 129, 130, 140, 153, 133, 123, 234, 123 };

	// initialize the salt buffer
	unsigned char salt_buffer[DIGESTSIZE] = {0};
	SHA256 hash;
	hash.update(salt_base, sizeof(salt_base));
	hash.update(username.c_str(), username.length());
	hash.finish(salt_buffer);

	// PBKDF2 to create the buffer
	unsigned char encrypted[DIGESTSIZE];
	pbkdf2(encrypted, (unsigned char*)password.c_str(), password.length(), salt_buffer, DIGESTSIZE, ITERATIONS);

	static const char base16[] = "0123456789ABCDEF";
	char hex[2 * DIGESTSIZE];
	for (int i = 0; i < DIGESTSIZE; ++i)
	{
		hex[i*2] = base16[encrypted[i] >> 4];		// 4 high bits
		hex[i*2 + 1] = base16[encrypted[i] & 0x0F];	// 4 low bits
	}
	return std::string(hex, sizeof(hex));
}
开发者ID:Rektosauros,项目名称:0ad,代码行数:30,代码来源:JSInterface_Lobby.cpp


示例5: clip

/**
 * Clear from clipboard data, that we put there previously
 * @return \c true, if we cleared our data, or stored data don't belong to us
*/
bool PWSclipboard::ClearCBData()
{
  wxMutexLocker clip(m_clipboardMutex);

  if (m_set && wxTheClipboard->Open()) {
    wxTextDataObject obj;
    if (wxTheClipboard->IsSupported(wxDF_UNICODETEXT) && wxTheClipboard->GetData(obj)) {
      StringX buf(obj.GetText().data(), obj.GetText().size());
      if (buf.length()) {
        // check if the data on the clipboard is the same we put there
        unsigned char digest[SHA256::HASHLEN];
        SHA256 ctx;

        ctx.Update(reinterpret_cast<const unsigned char *>(buf.c_str()), buf.length()*sizeof(wchar_t));
        ctx.Final(digest);
        if (memcmp(digest, m_digest, SHA256::HASHLEN) == 0) {
          // clear & reset
          wxTheClipboard->Clear();
          memset(m_digest, 0, SHA256::HASHLEN);
          m_set = false;
          // Also trash data in buffer and clipboard somehow?
          pws_os::Trace0(L"Cleared our data from buffer.\n");
        }
        else{
          pws_os::Trace0(L"Buffer doesn't contain our data. Nothing to clear.\n");
        }
      }
    }
    wxTheClipboard->Close();
  }
  return !m_set;
}
开发者ID:soundsrc,项目名称:pwsafe,代码行数:36,代码来源:pwsclip.cpp


示例6: ConvertFromBase58ShaSquare

Blob ConvertFromBase58ShaSquare(RCString s) {
	BigInteger bi = 0;
	for (const char *p=s; *p; ++p) {
		if (const char *q = strchr(s_pszBase58, *p)) {
			bi = bi*58 + BigInteger(q-s_pszBase58);
		} else
			Throw(E_INVALIDARG);
	}
	vector<byte> v((bi.Length+7)/8);
	bi.ToBytes(&v[0], v.size());
	if (v.size()>=2 && v.end()[-1]==0 && v.end()[-1]>=0x80)
		v.resize(v.size()-1);
	vector<byte> r;
	for (const char *p=s; *p==s_pszBase58[0]; ++p)
		r.push_back(0);
	r.resize(r.size()+v.size());
	std::reverse_copy(v.begin(), v.end(), r.end()-v.size());
	if (r.size() < 4)
		Throw(E_FAIL);
	SHA256 sha;
	HashValue hash = HashValue(sha.ComputeHash(sha.ComputeHash(ConstBuf(&r[0], r.size()-4))));
	if (memcmp(hash.data(), &r.end()[-4], 4))
		Throw(HRESULT_FROM_WIN32(ERROR_CRC));
	return Blob(&r[0], r.size()-4);
}
开发者ID:Groestlcoin,项目名称:Groestlcoin-WPF,代码行数:25,代码来源:base58.cpp


示例7: sha256_test

int sha256_test()
{
    SHA256 sha;
    byte   hash[SHA256::DIGEST_SIZE];

    testVector test_sha[] =
    {
        testVector("abc",
                 "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
                 "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
                 "\x15\xAD"),
        testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
                 "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
                 "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
                 "\x06\xC1")
    };

    int times( sizeof(test_sha) / sizeof(testVector) );
    for (int i = 0; i < times; ++i) {
        sha.Update(test_sha[i].input_, test_sha[i].inLen_);
        sha.Final(hash);

        if (memcmp(hash, test_sha[i].output_, SHA256::DIGEST_SIZE) != 0)
            return -1 - i;
    }

    return 0;
}
开发者ID:0x-ff,项目名称:libmysql-android,代码行数:28,代码来源:test.cpp


示例8: IncorporateEntropy

void RandomPool::IncorporateEntropy(const byte *input, size_t length)
{
	SHA256 hash;
	hash.Update(m_key, 32);
	hash.Update(input, length);
	hash.Final(m_key);
	m_keySet = false;
}
开发者ID:KayEss,项目名称:fost-crypto,代码行数:8,代码来源:randpool.cpp


示例9: dhAgree

bool provider::dhAgree(byte_block& agree, const byte_block& priv, const byte_block& pub)
{
	SHA256 hasher;
	byte_block _agree(dh_agree_block_size);
	if (!dh.Agree(_agree, priv, pub))
		return false;
	assert(_agree.SizeInBytes() == dh_agree_block_size);
	hasher.CalculateDigest(agree, _agree, dh_agree_block_size);
	return true;
}
开发者ID:xy12423,项目名称:messenger,代码行数:10,代码来源:crypto.cpp


示例10: ASSERT

void PWSrand::AddEntropy(unsigned char *bytes, unsigned int numBytes)
{
  ASSERT(bytes != nullptr);

  SHA256 s;

  s.Update(K, sizeof(K));
  s.Update(bytes, numBytes);
  s.Final(K);
}
开发者ID:soundsrc,项目名称:pwsafe,代码行数:10,代码来源:PWSrand.cpp


示例11: sizeof

void PWSrand::NextRandBlock()
{
  SHA256 s;
  s.Update(K, sizeof(K));
  s.Final(R);
  unsigned int *Kp = reinterpret_cast<unsigned int *>(K);
  unsigned int *Rp = reinterpret_cast<unsigned int *>(R);
  const int N = SHA256::HASHLEN / sizeof(uint32);

  Kp[0]++;

  for (int32 i = 0; i < N; i++)
    Kp[i] += Rp[i];
}
开发者ID:soundsrc,项目名称:pwsafe,代码行数:14,代码来源:PWSrand.cpp


示例12: getHash

const std::string getHash(std::string fname){
  std::ifstream f;
  f.open(fname.c_str());
  SHA256 digest;
  const size_t BufferSize = 144 * 7 * 1024;
  char * buffer = new char[BufferSize];
  if (f != NULL){
    f.read(buffer, BufferSize);//read(char *s, streamsize n)
    std::size_t numByte = size_t(f.gcount());//gcount(): return the number of characters extracted by the last unformatted input operation
    digest.add(buffer, numByte);
  }
  f.close();
  delete[] buffer;
  return digest.getHash();
}
开发者ID:apriljdai,项目名称:Data-Structure-and-Algorithms,代码行数:15,代码来源:deduplication.cpp


示例13:

void PWSfile::HashRandom256(unsigned char *p256)
{
  /**
   * This is for random data that will be written to the file directly.
   * The idea is to avoid directly exposing our generated randomness
   * to the attacker, since this might expose state of the RNG.
   * Therefore, we'll hash the randomness.
   *
   * As the names imply, this works on 256 bit (32 byte) arrays.
   */
  PWSrand::GetInstance()->GetRandomData(p256, 32);
  SHA256 salter;
  salter.Update(p256, 32);
  salter.Final(p256);
}
开发者ID:soundsrc,项目名称:pwsafe,代码行数:15,代码来源:PWSfile.cpp


示例14: ibRandomData

PWSrand::PWSrand()
  : ibRandomData(SHA256::HASHLEN)
{
  m_IsInternalPRNG = !pws_os::InitRandomDataFunction();

  SHA256 s;
  unsigned slen = 0;
  unsigned char *p;

  pws_os::GetRandomSeed(nullptr, slen);
  p = new unsigned char[slen];
  pws_os::GetRandomSeed(p, slen);
  s.Update(p, slen);
  delete[] p;
  s.Final(K);
}
开发者ID:soundsrc,项目名称:pwsafe,代码行数:16,代码来源:PWSrand.cpp


示例15: sha256

std::string sha256(const std::string& input)
{
    SHA256::uint8 digest[SHA256::DIGEST_SIZE];
    memset(digest,0,SHA256::DIGEST_SIZE);

    SHA256 ctx = SHA256();
    ctx.init();
    ctx.update( (SHA256::uint8*)input.c_str(), input.length());
    ctx._final(digest);

    char buf[2*SHA256::DIGEST_SIZE+1];
    buf[2*SHA256::DIGEST_SIZE] = 0;
    for (int i = 0; i < SHA256::DIGEST_SIZE; i++)
        sprintf(buf+i*2, "%02x", digest[i]);
    return std::string(buf);
}
开发者ID:gitter-badger,项目名称:Prattle,代码行数:16,代码来源:SHA256.cpp


示例16: CalcPbkdf2Hash

hashval CalcPbkdf2Hash(const UInt32 *pIhash, const ConstBuf& data, int idx) {
	SHA256 sha;

	size_t size = 16*4+data.Size+4;
	UInt32 *buf = (UInt32*)alloca(size);
	memset(buf, 0x36, 16*4);
	for (int i=0; i<8; ++i)
		buf[i] ^= pIhash[i];
	memcpy(buf+16, data.P, data.Size);
	buf[16+data.Size/4] = htobe32(idx);

	hashval hv = sha.ComputeHash(ConstBuf(buf, size));
	memset(buf, 0x5C, 16*4);
	for (int i=0; i<8; ++i)
		buf[i] ^= pIhash[i];
	memcpy(buf+16, hv.constData(), hv.size());
	return sha.ComputeHash(ConstBuf(buf, 64+hv.size()));
}
开发者ID:coinhelper,项目名称:coin,代码行数:18,代码来源:scrypt.cpp


示例17: ConvertToBase58ShaSquare

String ConvertToBase58ShaSquare(const ConstBuf& cbuf) {
	SHA256 sha;
	HashValue hash = HashValue(sha.ComputeHash(sha.ComputeHash(cbuf)));
	Blob v = cbuf + Blob(hash.data(), 4);
	vector<char> r;

	vector<byte> tmp(v.Size+1, 0);
	std::reverse_copy(v.begin(), v.end(), tmp.begin());
	for (BigInteger n(&tmp[0], tmp.size()); Sign(n);) {
		pair<BigInteger, BigInteger> pp = div(n, 58);
		n = pp.first;
		r.insert(r.begin(), s_pszBase58[explicit_cast<int>(pp.second)]);
	}

	for (int i=0; i<v.Size && !v.constData()[i]; ++i)
		r.insert(r.begin(), s_pszBase58[0]);
	return String(&r[0], r.size());
}
开发者ID:Groestlcoin,项目名称:Groestlcoin-WPF,代码行数:18,代码来源:base58.cpp


示例18: GetSha256ForFile

    std::string GetSha256ForFile(std::filesystem::path Filename)
    {
        SHA256 SHA;
        std::ifstream InStream(Filename.string());
        unsigned char tmpbuf[256];

        if (!InStream.is_open())
            return "";

        while (!InStream.eof())
        {
            InStream.read((char*)tmpbuf, 256);
            size_t cnt = InStream.gcount();

            SHA.add(tmpbuf, cnt);
        }

        return std::string(SHA.getHash());
    }
开发者ID:TomoAlien,项目名称:raindrop,代码行数:19,代码来源:Utility.cpp


示例19: CalcSCryptHash

CArray8UInt32 CalcSCryptHash(const ConstBuf& password) {
	ASSERT(password.Size == 80);

	SHA256 sha;

	hashval ihash = sha.ComputeHash(password);
	const UInt32 *pIhash = (UInt32*)ihash.constData();

	UInt32 x[32];
	for (int i=0; i<4; ++i) {
		hashval hv = CalcPbkdf2Hash(pIhash, password, i+1);
		memcpy(x+8*i, hv.constData(), 32);
	}
	AlignedMem am((1025*32)*sizeof(UInt32), 128);
	ScryptCore(x, (UInt32*)am.get());
	hashval hv = CalcPbkdf2Hash(pIhash, ConstBuf(x, sizeof x), 1);
	const UInt32 *p = (UInt32*)hv.constData();
	CArray8UInt32 r;
	for (int i=0; i<8; ++i)
		r[i] = p[i];
	return r;
}
开发者ID:coinhelper,项目名称:coin,代码行数:22,代码来源:scrypt.cpp


示例20: memset

PWSFileSig::PWSFileSig(const stringT &fname)
{
  const long THRESHOLD = 2048; // if file's longer than this, hash only head & tail

  m_length = 0;
  m_iErrorCode = PWSfile::SUCCESS;
  memset(m_digest, 0, sizeof(m_digest));
  FILE *fp = pws_os::FOpen(fname, _T("rb"));
  if (fp != NULL) {
    SHA256 hash;
    unsigned char buf[THRESHOLD];
    m_length = pws_os::fileLength(fp);
    // Minimum size for an empty V3 DB is 232 bytes - pre + post, no hdr or records!
    // Probably smaller for V1 & V2 DBs
    if (m_length > 232) {
      if (m_length <= THRESHOLD) {
        if (fread(buf, m_length, 1, fp) == 1) {
          hash.Update(buf, m_length);
          hash.Final(m_digest);
        }
      } else { // m_length > THRESHOLD
        if (fread(buf, THRESHOLD / 2, 1, fp) == 1 &&
            fseek(fp, -THRESHOLD / 2, SEEK_END) == 0 &&
            fread(buf + THRESHOLD / 2, THRESHOLD / 2, 1, fp) == 1) {
          hash.Update(buf, THRESHOLD);
          hash.Final(m_digest);
        }
      }
    } else {
      // File too small
      m_iErrorCode = PWSfile::TRUNCATED_FILE;
    }

    fclose(fp);
  } else {
    m_iErrorCode = PWSfile::CANT_OPEN_FILE;
  }
}
开发者ID:wcremeika,项目名称:thesis,代码行数:38,代码来源:PWSfile.cpp



注:本文中的SHA256类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ SHADER类代码示例发布时间:2022-05-31
下一篇:
C++ SHA1Hash类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap