コード例 #1
0
  SecureByteArray MessageDigestImpl<HASH>::digestImpl(const SecureByteArray& sa)
  {
    //ASSERT(sa.data());
    //ASSERT(sa.size());

    return digestImpl(sa.data(), sa.size());
  }
コード例 #2
0
 SecretKey::SecretKey(const NarrowString& alg,
   const SecureByteArray& bytes,
   const NarrowString& format)
   : m_algorithm(alg), m_secBlock(bytes.data(), bytes.size()), m_format(format)
 {
   ASSERT( !m_algorithm.empty() );
   ASSERT( m_secBlock.size() );
   ASSERT( !m_format.empty() );
 }
コード例 #3
0
  size_t MessageDigestImpl<HASH>::digestImpl(SecureByteArray& buf, size_t offset, size_t len)
   
  {
    //ASSERT(buf.data());
    //ASSERT(buf.size());
    //ASSERT(offset + len <= buf.size());

    return digestImpl(buf.data(), buf.size(), offset, len);
  }
コード例 #4
0
  SecureByteArray MessageDigestImpl<HASH>::digestImpl(const NarrowString& input)
  {
    //ASSERT(input.data());
    //ASSERT(input.length());

    // Our String classes do not have a getBytes() method.
    SecureByteArray sa = TextConvert::GetBytes(input, "UTF-8");
    return digestImpl(sa.data(), sa.size());
  }
コード例 #5
0
  void MessageDigestImpl<HASH>::updateImpl(const SecureByteArray& sa, size_t offset, size_t len)   
  {
    //ASSERT(sa.data());
    //ASSERT(sa.size());
    //ASSERT(len);
    //ASSERT(offset+len <= size);

    return updateImpl(sa.data(), sa.size(), offset, len);
  }
コード例 #6
0
ファイル: exporter.cpp プロジェクト: ChunHungLiu/Qt-SESAM
SecureByteArray Exporter::read(const SecureString &pwd)
{
  Q_D(Exporter);
  SecureByteArray plain;
  QFile file(d->filename);
  bool opened = file.open(QIODevice::ReadOnly);
  if (opened) {
    static const int MaxLineSize = 64 + 2;
    int state = 0;
    QByteArray b64;
    while (!file.atEnd()) {
      char buf[MaxLineSize];
      const qint64 bytesRead = file.readLine(buf, MaxLineSize);
      const QString line = QByteArray(buf, bytesRead).trimmed();
      switch (state) {
      case 0:
        if (line == PemPreamble) {
          state = 1;
        }
        else {
          qWarning() << "bad format";
        }
        break;
      case 1:
        if (line != PemEpilog) {
          b64.append(line.toUtf8());
        }
        else {
          state = 2;
        }
        break;
      case 2:
        // ignore trailing lines
        break;
      default:
        qWarning() << "Oops! Should never have gotten here.";
        break;
      }
    }
    file.close();
    SecureByteArray iv;
    SecureByteArray key;
    QByteArray imported = QByteArray::fromBase64(b64);
    QByteArray salt = imported.mid(0, Crypter::SaltSize);
    QByteArray cipher = imported.mid(Crypter::SaltSize);
    Crypter::makeKeyAndIVFromPassword(pwd.toUtf8(), salt, key, iv);
    CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption dec;
    dec.SetKeyWithIV(reinterpret_cast<const byte*>(key.constData()), key.size(), reinterpret_cast<const byte*>(iv.constData()));
    plain = SecureByteArray(cipher.size(), static_cast<char>(0));
    CryptoPP::ArraySource s(
          reinterpret_cast<const byte*>(cipher.constData()), cipher.size(),
          true,
          new CryptoPP::StreamTransformationFilter(
            dec,
            new CryptoPP::ArraySink(reinterpret_cast<byte*>(plain.data()), plain.size()),
            CryptoPP::StreamTransformationFilter::NO_PADDING
            )
          );
    Q_UNUSED(s); // just to please the compiler
  }
  return plain;
}
コード例 #7
0
 void MessageDigestImpl<HASH>::updateImpl(const NarrowString& str)   
 {
   // Our String classes do not have a getBytes() method.
   SecureByteArray sa = TextConvert::GetBytes(str, "UTF-8");
   updateImpl(sa.data(), sa.size());
 }
コード例 #8
0
 void MessageDigestImpl<HASH>::updateImpl(const SecureByteArray& input)   
 {
   updateImpl(input.data(), input.size());
 }
コード例 #9
0
 /**
  * Creates an IvParameterSpec object using the first len bytes in iv,
  * beginning at offset inclusive, as the IV.
  */
 IvParameterSpec::IvParameterSpec(const SecureByteArray& iv, size_t offset, size_t len)
   : m_iv(create_secure_array(iv.data(), iv.size(), offset, len))
 {
   ASSERT(m_iv.data());
   ASSERT(m_iv.size());
 }
コード例 #10
0
 /**
  * Creates an IvParameterSpec object using the bytes in iv as the IV.
  */
 IvParameterSpec::IvParameterSpec(const SecureByteArray& iv)
   : m_iv(create_secure_array(iv.data(), iv.size(), 0, iv.size()))
 {
   ASSERT(m_iv.data());
   ASSERT(m_iv.size());
 }