⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgp_s2k.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** OpenPGP S2K Source File                        ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/pgp_s2k.h>#include <botan/lookup.h>namespace Botan {/************************************************** Derive a key using the OpenPGP S2K algorithm   **************************************************/SymmetricKey OpenPGP_S2K::derive_key(const std::string& passphrase,                                     u32bit keylen) const   {   static const byte ZERO_BYTE[1] = { 0 };   SecureVector<byte> key(keylen), hash_buf;   u32bit pass = 0, generated = 0,          total_size = passphrase.size() + salt.size();   u32bit to_hash = std::max(iterations(), total_size);   hash->clear();   while(keylen > generated)      {      for(u32bit j = 0; j != pass; j++)         hash->update(ZERO_BYTE, 1);      u32bit left = to_hash;      while(left >= total_size)         {         hash->update(salt, salt.size());         hash->update(passphrase);         left -= total_size;         }      if(left <= salt.size())         hash->update(salt, left);      else         {         hash->update(salt, salt.size());         left -= salt.size();         hash->update((const byte*)passphrase.c_str(), left);         }      hash_buf = hash->final();      key.copy(generated, hash_buf, hash->OUTPUT_LENGTH);      generated += hash->OUTPUT_LENGTH;      pass++;      }   return SymmetricKey(key, key.size());   }/************************************************** OpenPGP S2K Constructor                        **************************************************/OpenPGP_S2K::OpenPGP_S2K(const std::string& h, u32bit i, u32bit salt_size) :   S2K(true)   {   hash = get_hash(h);   set_iterations(i);   if(salt_size)      new_random_salt(salt_size);   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -