diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-10 12:52:06 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-10 12:52:06 +0200 |
| commit | f6586ae894673b561455de5044d2ff31f6a0ef94 (patch) | |
| tree | 854df037b2f8b5c034bdb0b794c2e19ee47f9fe7 /src/crypt/cryptaes.cpp | |
| parent | 74bdec2ff94eec373eb358c00437d55fe44c9238 (diff) | |
| download | IT-Sicherheit-master.tar.gz IT-Sicherheit-master.zip | |
Diffstat (limited to 'src/crypt/cryptaes.cpp')
| -rw-r--r-- | src/crypt/cryptaes.cpp | 72 |
1 files changed, 7 insertions, 65 deletions
diff --git a/src/crypt/cryptaes.cpp b/src/crypt/cryptaes.cpp index b74ae03..0129c31 100644 --- a/src/crypt/cryptaes.cpp +++ b/src/crypt/cryptaes.cpp @@ -32,80 +32,22 @@ const EVP_CIPHER *CryptAes::algorithm() void CryptAes::encrypt() { - EVP_MD_CTX *ctx; + m_key = CryptEngine::createPasswordHash(m_key); - /* Create and initialise the context */ - if (!(ctx = EVP_MD_CTX_create())) - { - handleOpenSslError(); - } - - /* Initialise the encryption operation. IMPORTANT - ensure you use a key - * and IV size appropriate for your cipher */ - if (1 != EVP_DigestInit_ex(ctx, EVP_sha256(), NULL)) - { - handleOpenSslError(); - } - - /* Provide the message to be encrypted, and obtain the encrypted output. - * EVP_EncryptUpdate can be called multiple times if necessary - */ - if (1 != EVP_DigestUpdate(ctx, m_key.data(), m_key.size())) - { - handleOpenSslError(); - } - - m_key = QByteArray(256, 0); - - /* Finalise the encryption. Further ciphertext bytes may be written at - * this stage. - */ - if (1 != EVP_DigestFinal_ex(ctx, (unsigned char *) m_key.data(), NULL)) - { - handleOpenSslError(); - } - - EVP_MD_CTX_destroy(ctx); + m_iv = CryptEngine::createRandomIv(IVLENGTH); CryptClassEvp::encrypt(); + + m_cryptText = m_iv + m_cryptText; } void CryptAes::decrypt() { - EVP_MD_CTX *ctx; - - /* Create and initialise the context */ - if (!(ctx = EVP_MD_CTX_create())) - { - handleOpenSslError(); - } - - /* Initialise the encryption operation. IMPORTANT - ensure you use a key - * and IV size appropriate for your cipher */ - if (1 != EVP_DigestInit_ex(ctx, EVP_sha256(), NULL)) - { - handleOpenSslError(); - } + m_key = CryptEngine::createPasswordHash(m_key); - /* Provide the message to be encrypted, and obtain the encrypted output. - * EVP_EncryptUpdate can be called multiple times if necessary - */ - if (1 != EVP_DigestUpdate(ctx, m_key.data(), m_key.size())) - { - handleOpenSslError(); - } - - m_key = QByteArray(256, 0); - - /* Finalise the encryption. Further ciphertext bytes may be written at - * this stage. - */ - if (1 != EVP_DigestFinal_ex(ctx, (unsigned char *) m_key.data(), NULL)) - { - handleOpenSslError(); - } + m_iv = m_cryptText.left(IVLENGTH); - EVP_MD_CTX_destroy(ctx); + m_cryptText = m_cryptText.remove(0, IVLENGTH); CryptClassEvp::decrypt(); } |
