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