sync with tizen_2.0
[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
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 an 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          *      @exception      E_SUCCESS                               The method is successful.
92          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
93          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
94          */
95         virtual result SetPublicKey(const Tizen::Security::IKey& key);
96
97         /**
98          *      Encrypts the data (single-part).
99          *
100          *      @since          2.0
101          *
102          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
103          *                              else @c null if an error occurs
104          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
105          *      @exception      E_SUCCESS                               The method is successful.
106          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
107          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
108          *      @exception      E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
109          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
110          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
111          *      @exception      E_SYSTEM                                A system error has occurred. @n
112          *                                                                              The method has failed to operate with the OpenSSL library, or
113          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
114          * @remarks The specific error code can be accessed using the GetLastResult() method.
115          */
116         virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
117
118         /**
119          *      Decrypts the data (single-part).
120          *
121          *      @since          2.0
122          *
123          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
124          *                              else @c null if an error occurs
125          *  @param[in]  input                                   An instance of Tizen::Base::ByteBuffer
126          *      @exception      E_SUCCESS                               The method is successful.
127          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
128          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
129          *      @exception      E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
130          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
131          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
132          *      @exception      E_SYSTEM                                A system error has occurred. @n
133          *                                                                              The method has failed to operate with the OpenSSL library, or
134          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
135          * @remarks The specific error code can be accessed using the GetLastResult() method.
136          */
137         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
138
139 private:
140
141         //
142         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
143         //
144         // @since 2.0
145         //
146         RsaCipher(const RsaCipher& rhs);
147
148         //
149         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
150         //
151         // @since 2.0
152         //
153         RsaCipher& operator =(const RsaCipher& rhs);
154
155 private:
156         Tizen::Base::ByteBuffer __privateKey;
157         Tizen::Base::ByteBuffer __publicKey;
158
159         class _RsaCipherImpl* __pRsaCipherImpl;
160         friend class _RsaCipherImpl;
161
162 }; //RsaCipher
163
164 } } } //Tizen::Security::Crypto
165
166 #endif //_FSEC_CRYPTO_RSA_CIPHER_H_