OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLCrypto.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLCRYPTO_HPP
12#define OPENXLSX_XLCRYPTO_HPP
13
14#pragma once
15
16#include <vector>
17#include <string>
18#include <cstdint>
19#include "OpenXLSX-Exports.hpp"
20#include "XLException.hpp"
21#include <gsl/span>
22
23namespace OpenXLSX {
24
30 OPENXLSX_EXPORT bool isEncryptedDocument(gsl::span<const uint8_t> data);
31
38 OPENXLSX_EXPORT std::vector<uint8_t> decryptDocument(gsl::span<const uint8_t> data, const std::string& password);
39
46 OPENXLSX_EXPORT std::vector<uint8_t> encryptDocument(gsl::span<const uint8_t> zipData, const std::string& password);
47
48 // Advanced Crypto routines for internal use
49 namespace Crypto {
50 std::vector<uint8_t> readCfbStream(gsl::span<const uint8_t> data, const std::string& streamName);
51 std::vector<uint8_t> decryptAgilePackage(gsl::span<const uint8_t> encryptionInfo,
52 gsl::span<const uint8_t> encryptedPackage,
53 const std::string& password);
54 std::vector<uint8_t> encryptStandardPackage(gsl::span<const uint8_t> zipData, const std::string& password);
55 std::vector<uint8_t> encryptAgilePackage(gsl::span<const uint8_t> zipData, const std::string& password);
56 std::vector<uint8_t> decryptStandardPackage(gsl::span<const uint8_t> encryptionInfo,
57 gsl::span<const uint8_t> encryptedPackage,
58 const std::string& password);
59
60 std::vector<uint8_t> aes256CbcDecrypt(gsl::span<const uint8_t> data, gsl::span<const uint8_t> key, gsl::span<const uint8_t> iv);
61 std::vector<uint8_t> sha512Hash(gsl::span<const uint8_t> data);
62 std::vector<uint8_t> generateAgileHash(const std::string& password, gsl::span<const uint8_t> salt, int spinCount);
63 }
64} // namespace OpenXLSX
65
66#endif // OPENXLSX_XLCRYPTO_HPP
Definition XLCrypto.hpp:49
std::vector< uint8_t > encryptStandardPackage(gsl::span< const uint8_t > zipData, const std::string &password)
Definition XLCrypto.cpp:277
std::vector< uint8_t > encryptAgilePackage(gsl::span< const uint8_t > zipData, const std::string &password)
Definition XLCrypto.cpp:595
std::vector< uint8_t > decryptStandardPackage(gsl::span< const uint8_t > encryptionInfo, gsl::span< const uint8_t > encryptedPackage, const std::string &password)
Definition XLCrypto.cpp:747
std::vector< uint8_t > generateAgileHash(const std::string &password, gsl::span< const uint8_t > salt, int spinCount)
Definition XLCrypto.cpp:433
std::vector< uint8_t > readCfbStream(gsl::span< const uint8_t > data, const std::string &streamName)
Definition XLCrypto.cpp:62
std::vector< uint8_t > sha512Hash(gsl::span< const uint8_t > data)
Definition XLCrypto.cpp:421
std::vector< uint8_t > decryptAgilePackage(gsl::span< const uint8_t > encryptionInfo, gsl::span< const uint8_t > encryptedPackage, const std::string &password)
Definition XLCrypto.cpp:461
std::vector< uint8_t > aes256CbcDecrypt(gsl::span< const uint8_t > data, gsl::span< const uint8_t > key, gsl::span< const uint8_t > iv)
Definition XLCrypto.cpp:396
Definition IXLCellProvider.hpp:24
OPENXLSX_EXPORT std::vector< uint8_t > decryptDocument(gsl::span< const uint8_t > data, const std::string &password)
High-level API to decrypt an entire document from a buffer.
Definition XLCrypto.cpp:44
OPENXLSX_EXPORT bool isEncryptedDocument(gsl::span< const uint8_t > data)
Checks if a given byte stream represents an OLE CFB document.
Definition XLCrypto.cpp:32
OPENXLSX_EXPORT std::vector< uint8_t > encryptDocument(gsl::span< const uint8_t > zipData, const std::string &password)
High-level API to encrypt a ZIP package into a CFB container.
Definition XLCrypto.cpp:38