Apply reviewed doxygen header
[platform/framework/native/appfw.git] / inc / FSecCryptoRsaCipher.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 /**
18  * @file                FSecCryptoRsaCipher.h
19  * @brief               This is the header file for the %RsaCipher class.
20  *
21  * This header file contains the declarations of the %RsaCipher class.
22  */
23 #ifndef _FSEC_CRYPTO_RSA_CIPHER_H_
24 #define _FSEC_CRYPTO_RSA_CIPHER_H_
25
26 #include <FSecCryptoIAsymmetricCipher.h>
27 #include <FSecIPublicKey.h>
28 #include <FSecIPrivateKey.h>
29 #include <FBase.h>
30
31
32 namespace Tizen { namespace Security { namespace Crypto
33 {
34
35 /**
36  *      @class          RsaCipher
37  *      @brief          This class provides methods for encryption and decryption using the Rivest Shamir Adleman (RSA) algorithm.
38  *
39  *      @since          2.0
40  *
41  *      The %RsaCipher class provides methods to encrypt and decrypt messages, and is used in the asymmetric cipher
42  *      operations. @n
43  *
44  *      For more information on using the Rivest Shamir Adleman (RSA) algorithm for asymmetric ciphers, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
45  *
46  *      @see Tizen::Security::KeyPair
47  *      @see Tizen::Security::IPublicKey
48  *      @see Tizen::Security::IPrivateKey
49  */
50 class _OSP_EXPORT_ RsaCipher
51         : public virtual IAsymmetricCipher
52         , public Tizen::Base::Object
53 {
54
55 public:
56         /**
57          *      This is the default constructor for this class.
58          *
59          *      @since          2.0
60          */
61         RsaCipher(void);
62
63         /**
64          *      This destructor overrides Tizen::Base::Object::~Object().
65          *
66          *      @since          2.0
67          */
68         virtual ~RsaCipher(void);
69
70         /**
71          *      Sets the asymmetric private key for encryption or decryption.
72          *
73          *      @since          2.0
74          *
75          *      @return         An error code
76          *      @param[in]      key                                             An instance of IKey @n
77          *                                                                              The @c key can be in PEM/DER/PKCS8 format only.
78          *      @exception      E_SUCCESS                               The method is successful.
79          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
80          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
81          */
82         virtual result SetPrivateKey(const Tizen::Security::IKey& key);
83
84         /**
85          *      Sets the asymmetric public key for encryption or decryption.
86          *
87          *      @since          2.0
88          *
89          *      @return         An error code
90          *      @param[in]      key                                             An instance of IKey
91          *                                                                              The @c key can be in PEM/DER/X509 public key format only.
92          *      @exception      E_SUCCESS                               The method is successful.
93          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
94          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
95          */
96         virtual result SetPublicKey(const Tizen::Security::IKey& key);
97
98         /**
99          *      Encrypts the data (single-part).
100          *
101          *      @since          2.0
102          *
103          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
104          *                              else @c null if an error occurs
105          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
106          *      @exception      E_SUCCESS                               The method is successful.
107          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
108          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
109          *      @exception      E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
110          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
111          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
112          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
113          *                                                                              - A system error has occurred.
114          *                                                                              - The method has failed to operate with the OpenSSL library.
115          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
116          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
117          */
118         virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
119
120         /**
121          *      Decrypts the data (single-part).
122          *
123          *      @since          2.0
124          *
125          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
126          *                              else @c null if an error occurs
127          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
128          *      @exception      E_SUCCESS                               The method is successful.
129          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
130          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
131          *      @exception      E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
132          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
133          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
134          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
135          *                                                                              - A system error has occurred.
136          *                                                                              - The method has failed to operate with the OpenSSL library.
137          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
138          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
139          */
140         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
141
142 private:
143
144         //
145         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
146         //
147         // @since 2.0
148         //
149         RsaCipher(const RsaCipher& rhs);
150
151         //
152         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
153         //
154         // @since 2.0
155         //
156         RsaCipher& operator =(const RsaCipher& rhs);
157
158 private:
159         Tizen::Base::ByteBuffer __privateKey;
160         Tizen::Base::ByteBuffer __publicKey;
161
162         class _RsaCipherImpl* __pRsaCipherImpl;
163         friend class _RsaCipherImpl;
164
165 }; //RsaCipher
166
167 } } } //Tizen::Security::Crypto
168
169 #endif //_FSEC_CRYPTO_RSA_CIPHER_H_