Merge "Update doxygen of TimeZone." into devel_3.0_main
[platform/framework/native/appfw.git] / inc / FSecCryptoRsaSignature.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                FSecCryptoRsaSignature.h
19  * @brief               This is the header file for the %RsaSignature class.
20  *
21  * This header file contains the declarations of the %RsaSignature class.
22  */
23 #ifndef _FSEC_CRYPTO_RSA_SIGNATURE_H_
24 #define _FSEC_CRYPTO_RSA_SIGNATURE_H_
25
26 #include <FSecCryptoISignature.h>
27 #include <FBase.h>
28
29
30 namespace Tizen { namespace Security { namespace Crypto
31 {
32
33 /**
34  *      @class          RsaSignature
35  *      @brief          This class implements the Rivest Shamir Adleman (RSA) signatures.
36  *
37  *      @since          2.0
38  *
39  *      The %RsaSignature class implements the Rivest Shamir Adleman (RSA) signatures. @n
40  *
41  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
42  *
43  *      @see ISignature
44  *      @see IKeyPairGenerator
45  *      @see KeyPair
46  *      @see IPublicKey
47  *      @see IPrivateKey
48  *      @see PublicKey
49  *      @see PrivateKey
50  */
51 class _OSP_EXPORT_ RsaSignature
52         : public virtual ISignature
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         RsaSignature(void);
63
64         /**
65          *      This destructor overrides Tizen::Base::Object::~Object().
66          *
67          *      @since          2.0
68          */
69         virtual ~RsaSignature(void);
70
71         /**
72          *      Sets an asymmetric private key for signature.
73          *
74          *      @since          2.0
75          *
76          *      @return         An error code
77          *      @param[in]      key                                                     An instance of IKey.
78          *                                                                                      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 verification.
87          *
88          *      @since          2.0
89          *
90          *      @return         An error code
91          *      @param[in]      key                                                     An instance of IKey
92          *                                                                                      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          *      Signs the data. @n
101          *      The %SignN() method only supports sha1withRsa for signing the data
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_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* SignN(const Tizen::Base::ByteBuffer& input);
117
118         /**
119          *      Signs the data. @n
120          *      The %SignN() method provides the additional option to developer for setting digest algorithm that is needed for signing the data
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          *      @param[in]      algorithm                                       An instance of Tizen::Base::String that contains the digest algorithm,
128          *                                                                                      valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
129          *      @exception      E_SUCCESS                                       The method is successful.
130          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
131          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
132          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
133          *      @exception      E_UNSUPPORTED_ALGORITHM         The specified algorithm is not supported.
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         Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input, const Tizen::Base::String& algorithm);
140
141         /**
142          *      Verifies the data. @n
143          *      The verification is done by comparing the @c signedData to the signature created by the @c data. @
144          *      The %Verify() method only supports sha1withRsa for verifying the signed data
145          *
146          *      @since          2.0
147          *
148          *      @return         @c true if the signed data is correct, @n
149          *                              else @c false
150          *      @param[in]      data                                            An instance of Tizen::Base::ByteBuffer that contains the original data
151          *      @param[in]      signedData                                      A instance of Tizen::Base::ByteBuffer that contains the signed data
152          *      @exception      E_SUCCESS                                       The method is successful.
153          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
154          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
155          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
156          *      @exception      E_SYSTEM                                        A system error has occurred. @n
157          *                                                                                      The method has failed to operate with the OpenSSL library, or
158          *                                                                                      the Tizen::Base::ByteBuffer operation has failed.
159          *  @remarks    The specific error code can be accessed using the GetLastResult() method.
160          */
161         virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData);
162
163         /**
164          *      Verifies the data. @n
165          *      The verification is done by comparing the @c signedData to the signature created by the @c data. @n
166          *      The %Verify() method provides the additional option to developer for setting digest algorithm that is needed for verifying the signed data
167          *
168          *      @since          2.0
169          *
170          *      @return         @c true if the signed data is correct, @n
171          *                              else @c false
172          *      @param[in]      data                                            An instance of Tizen::Base::ByteBuffer that contains the original data
173          *      @param[in]      signedData                                      A instance of Tizen::Base::ByteBuffer that contains the signed data
174          *      @param[in]      algorithm                                       An instance of Tizen::Base::String that contains the digest algorithm,
175          *                                                                                      valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
176          *      @exception      E_SUCCESS                                       The method is successful.
177          *      @exception      E_INVALID_ARG                           The input Tizen::Base::ByteBuffer is empty or contains invalid data.
178          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
179          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
180          *      @exception      E_UNSUPPORTED_ALGORITHM         The specified algorithm is not supported.
181          *      @exception      E_SYSTEM                                        A system error has occurred. @n
182          *                                                                                      The method has failed to operate with the OpenSSL library, or
183          *                                                                                      the Tizen::Base::ByteBuffer operation has failed.
184          *  @remarks    The specific error code can be accessed using the GetLastResult() method.
185          */
186         bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData, const Tizen::Base::String& algorithm);
187
188 private:
189
190         //
191         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
192         //
193         // @since 2.0
194         //
195         RsaSignature(const RsaSignature& rhs);
196
197         //
198         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
199         //
200         // @since 2.0
201         //
202         RsaSignature& operator =(const RsaSignature& rhs);
203
204 private:
205         Tizen::Base::ByteBuffer __privateKey;
206         Tizen::Base::ByteBuffer __publicKey;
207
208         class _RsaSignatureImpl* __pRsaSignatureImpl;
209         friend class _RsaSignatureImpl;
210
211 }; //RsaSignature
212
213 } } } //Tizen::Security::Crypto
214
215 #endif //_FSEC_CRYPTO_RSA_SIGNATURE_H_