Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
DES.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19
20#pragma once
21
22#include <sese/Config.h>
24
25namespace sese::security::evp {
26
29class SESE_DEPRECATED_WITH("DES 加密已从 OpenSSL 中移除") DESEncrypter final : public Crypter {
30public:
32 enum class Type {
33 ECB,
34 CBC,
35 CFB1,
36 CFB8,
37 CFB64,
38 EDE,
39 EDE3,
40 };
41
42 DESEncrypter(Type type, const std::array<unsigned char, 8> &key);
43
44 DESEncrypter(Type type, const std::string &key);
45
46 ~DESEncrypter() override;
47
48 int update(void *out, int &out_len, const void *in, int in_len) const noexcept override;
49
50 int final(void *out, int &out_len) const noexcept override;
51
52private:
53 void *ctx;
54 unsigned char key[8];
55};
56
59class SESE_DEPRECATED_WITH("DES 加密已从 OpenSSL 中移除") DESDecrypter final : public Crypter {
60public:
61#if defined(__clang__)
62#pragma clang diagnostic push
63#pragma clang diagnostic ignored "-Wdeprecated-declarations"
64#elif defined(_MSC_VER)
65#pragma warning(disable : 4996)
66#elif defined(__GNUC__)
67#pragma GCC diagnostic push
68#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
69#endif
70 using Type = DESEncrypter::Type; // NOLINT
71#if defined(__clang__)
72#pragma clang diagnostic pop
73#elif defined(__GNUC__)
74#pragma GCC diagnostic pop
75#endif
76
77 DESDecrypter(Type type, const std::array<unsigned char, 8> &key);
78
79 DESDecrypter(Type type, const std::string &key);
80
81 ~DESDecrypter() override;
82
83 int update(void *out, int &out_len, const void *in, int in_len) const noexcept override;
84
85 int final(void *out, int &out_len) const noexcept override;
86
87private:
88 void *ctx;
89 unsigned char key[8];
90};
91
92} // namespace sese::security::evp