1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 #include <alibabacloud/oss/encryption/Cipher.h>
19 #include <openssl/evp.h>
20 
21 namespace AlibabaCloud
22 {
23 namespace OSS
24 {
25     class SymmetricCipherOpenssl : public  SymmetricCipher
26     {
27     public:
28         ~SymmetricCipherOpenssl();
29         SymmetricCipherOpenssl(const EVP_CIPHER* cipher, CipherAlgorithm algo, CipherMode mode, CipherPadding pad);
30 
31         virtual void EncryptInit(const ByteBuffer& key, const ByteBuffer& iv);
32         virtual ByteBuffer Encrypt(const ByteBuffer& data);
33         virtual int Encrypt(unsigned char * dst, int dstLen, const unsigned char* src, int srcLen);
34         virtual ByteBuffer EncryptFinish();
35 
36         virtual void DecryptInit(const ByteBuffer& key, const ByteBuffer& iv);
37         virtual ByteBuffer Decrypt(const ByteBuffer& data);
38         virtual int Decrypt(unsigned char * dst, int dstLen, const unsigned char* src, int srcLen);
39         virtual ByteBuffer DecryptFinish();
40 
41     private:
42         EVP_CIPHER_CTX* encryptCtx_;
43         EVP_CIPHER_CTX* decryptCtx_;
44         const EVP_CIPHER* cipher_;
45         int blockSize_;
46     };
47 
48     class AsymmetricCipherOpenssl : public  AsymmetricCipher
49     {
50     public:
51         ~AsymmetricCipherOpenssl();
52         AsymmetricCipherOpenssl(CipherAlgorithm algo, CipherMode mode, CipherPadding pad);
53 
54         virtual ByteBuffer Encrypt(const ByteBuffer& data);
55         virtual ByteBuffer Decrypt(const ByteBuffer& data);
56     private:
57     };
58 }
59 }
60