Merge "update doxygen comments" into tizen_2.1
[platform/framework/native/appfw.git] / inc / FSecCryptoRsaCipher.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FSecCryptoRsaCipher.h
20  * @brief               This is the header file for the %RsaCipher class.
21  *
22  * This header file contains the declarations of the %RsaCipher class.
23  */
24 #ifndef _FSEC_CRYPTO_RSA_CIPHER_H_
25 #define _FSEC_CRYPTO_RSA_CIPHER_H_
26
27 #include <FSecCryptoIAsymmetricCipher.h>
28 #include <FSecIPublicKey.h>
29 #include <FSecIPrivateKey.h>
30 #include <FBase.h>
31
32
33 namespace Tizen { namespace Security { namespace Crypto
34 {
35
36 /**
37  *      @class          RsaCipher
38  *      @brief          This class provides methods for encryption and decryption using the Rivest Shamir Adleman (RSA) algorithm.
39  *
40  *      @since          2.0
41  *
42  *      The %RsaCipher class provides methods to encrypt and decrypt messages, and is used in the asymmetric cipher
43  *      operations. @n
44  *
45  *      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>.
46  *
47  *      @see Tizen::Security::KeyPair
48  *      @see Tizen::Security::IPublicKey
49  *      @see Tizen::Security::IPrivateKey
50  */
51 class _OSP_EXPORT_ RsaCipher
52         : public virtual IAsymmetricCipher
53         , public Tizen::Base::Object
54 {
55
56 public:
57         /**
58          *      This is the default constructor for this class.
59          *
60          *      @since          2.0
61          */
62         RsaCipher(void);
63
64         /**
65          *      This destructor overrides Tizen::Base::Object::~Object().
66          *
67          *      @since          2.0
68          */
69         virtual ~RsaCipher(void);
70
71         /**
72          *      Sets an asymmetric private key for encryption or decryption.
73          *
74          *      @since          2.0
75          *
76          *      @return         An error code
77          *      @param[in]      key                                             An instance of IKey @n
78          *                                                                              The @c key can be in PEM/DER/PKCS8 format only.
79          *      @exception      E_SUCCESS                               The method is successful.
80          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
81          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
82          */
83         virtual result SetPrivateKey(const Tizen::Security::IKey& key);
84
85         /**
86          *      Sets an asymmetric public key for encryption or decryption.
87          *
88          *      @since          2.0
89          *
90          *      @return         An error code
91          *      @param[in]      key                                             An instance of IKey
92          *                                                                              The @c key can be in PEM/DER/X509 public key format only.
93          *      @exception      E_SUCCESS                               The method is successful.
94          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
95          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
96          */
97         virtual result SetPublicKey(const Tizen::Security::IKey& key);
98
99         /**
100          *      Encrypts the data (single-part).
101          *
102          *      @since          2.0
103          *
104          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
105          *                              else @c null if an error occurs
106          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
107          *      @exception      E_SUCCESS                               The method is successful.
108          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
109          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
110          *      @exception      E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
111          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
112          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
113          *      @exception      E_SYSTEM                                A system error has occurred. @n
114          *                                                                              The method has failed to operate with the OpenSSL library, or
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                                A system error has occurred. @n
135          *                                                                              The method has failed to operate with the OpenSSL library, or
136          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
137          * @remarks The specific error code can be accessed using the GetLastResult() method.
138          */
139         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
140
141 private:
142
143         //
144         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
145         //
146         // @since 2.0
147         //
148         RsaCipher(const RsaCipher& rhs);
149
150         //
151         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
152         //
153         // @since 2.0
154         //
155         RsaCipher& operator =(const RsaCipher& rhs);
156
157 private:
158         Tizen::Base::ByteBuffer __privateKey;
159         Tizen::Base::ByteBuffer __publicKey;
160
161         class _RsaCipherImpl* __pRsaCipherImpl;
162         friend class _RsaCipherImpl;
163
164 }; //RsaCipher
165
166 } } } //Tizen::Security::Crypto
167
168 #endif //_FSEC_CRYPTO_RSA_CIPHER_H_