Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
RC4.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
7
8#include "RC4.h"
9
10using std::byte;
11
12using namespace Stroika::Foundation;
14using namespace Stroika::Foundation::Cryptography;
15using namespace Stroika::Foundation::Cryptography::Encoding;
16using namespace Stroika::Foundation::Cryptography::Encoding::Algorithm;
17
18using Memory::BLOB;
19
20#if qStroika_HasComponent_OpenSSL
21namespace {
22 OpenSSLCryptoParams cvt_ (const BLOB& key)
23 {
24 return OpenSSLCryptoParams{Providers::OpenSSL::CipherAlgorithms::kRC4, key, BLOB{}};
25 }
26}
27#endif
28
29#if qStroika_HasComponent_OpenSSL
30/*
31 ********************************************************************************
32 ***************************** Algorithm::DecodeRC4 *****************************
33 ********************************************************************************
34 */
35Streams::InputStream::Ptr<byte> Algorithm::DecodeRC4 (const BLOB& key, const Streams::InputStream::Ptr<byte>& in)
36{
37 return OpenSSLInputStream::New (cvt_ (key), Direction::eDecrypt, in);
38}
39Memory::BLOB Algorithm::DecodeRC4 (const BLOB& key, const BLOB& in)
40{
41 return DecodeRC4 (key, in.As<Streams::InputStream::Ptr<byte>> ()).ReadAll ();
42}
43#endif
44
45#if qStroika_HasComponent_OpenSSL
46/*
47 ********************************************************************************
48 ****************************** Algorithm::EncodeRC4 ****************************
49 ********************************************************************************
50 */
51Streams::InputStream::Ptr<byte> Algorithm::EncodeRC4 (const BLOB& key, const Streams::InputStream::Ptr<byte>& in)
52{
53 return OpenSSLInputStream::New (cvt_ (key), Direction::eEncrypt, in);
54}
55BLOB Algorithm::EncodeRC4 (const Memory::BLOB& key, const BLOB& in)
56{
57 return EncodeRC4 (key, in.As<Streams::InputStream::Ptr<byte>> ()).ReadAll ();
58}
59#endif
60
61#if qStroika_HasComponent_OpenSSL
62/*
63 ********************************************************************************
64 **************************** Algorithm::RC4Encoder *****************************
65 ********************************************************************************
66 */
67Streams::OutputStream::Ptr<byte> Algorithm::RC4Decoder (const Memory::BLOB& key, const Streams::OutputStream::Ptr<byte>& out)
68{
69 return OpenSSLOutputStream::New (cvt_ (key), Direction::eDecrypt, out);
70}
71#endif
72
73#if qStroika_HasComponent_OpenSSL
74/*
75 ********************************************************************************
76 ****************************** Algorithm::RC4Encoder ***************************
77 ********************************************************************************
78 */
79Streams::OutputStream::Ptr<byte> Algorithm::RC4Encoder (const Memory::BLOB& key, const Streams::OutputStream::Ptr<byte>& out)
80{
81 return OpenSSLOutputStream::New (cvt_ (key), Direction::eEncrypt, out);
82}
83#endif
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.