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