Apply string localization for web
[platform/framework/native/appfw.git] / inc / FSecRsaKeyConverter.h
1 //
2 // Copyright (c) 2013 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                FSecRsaKeyConverter.h
19  * @brief               This is the header file for the %RsaKeyConverter class.
20  *
21  * This header file contains the declarations of the %RsaKeyConverter class.
22  */
23
24 #ifndef _FSEC_RSA_KEY_CONVERTER_H_
25 #define _FSEC_RSA_KEY_CONVERTER_H_
26
27 #include <FSecIPublicKey.h>
28 #include <FSecIPrivateKey.h>
29
30 namespace Tizen { namespace Security
31 {
32
33 /**
34  *      @enum   RsaKeyFormat
35  *
36  *      Defines the types of rsa key format.
37  *
38  *      @since          2.1
39  */
40 enum RsaKeyFormat
41 {
42         RSA_KEY_FORMAT_PKCS01_PRIVATE_KEY = 0,  /**< The rsa key format is PKCS1 private key */
43         RSA_KEY_FORMAT_PKCS01_PUBLIC_KEY = 1,   /**< The rsa key format is PKCS1 public key */
44         RSA_KEY_FORMAT_PKCS08_PRIVATE_KEY = 2,  /**< The rsa key format is PKCS8 private key */
45         RSA_KEY_FORMAT_X509_PUBLIC_KEY = 3,             /**< The rsa key format is X509 public key */
46         RSA_KEY_FORMAT_UNKNOWN = 0xffffffff             /**< The rsa key format is unknown */
47 }; //RsaKeyFormat;
48
49 /**
50  *      @class          RsaKeyConverter
51  *      @brief          This class provides methods for converting the RSA public/private key in multiple key formats and multiple encoding formats.
52  *
53  *      @since          2.1
54  *
55  *      The %RsaKeyConverter class provides support for converting the RSA public/private key in multiple key formats and multiple encoding formats. @n
56  *      The supported RSA key formats are PKCS1/PKCS8/X509. @n
57  *      The supported encoding formats are DER/PEM.
58  */
59
60 class _OSP_EXPORT_ RsaKeyConverter
61 {
62
63 public:
64         /**
65          *      Generates an RSA encoded private key in the passed input RSA key format. @n
66          *      If the input private key is in PEM encoded format, then the output RSA private key will be PEM encoded; if it is in DER encoded format,
67          *      then the output RSA private key will be DER encoded.
68          *
69          *      @since          2.1
70          *
71          *      @return         A pointer to the encoded Tizen::Base::ByteBuffer instance, @n
72          *                              else @c null if the method fails to convert the private key in the passed input format
73          *      @param[in]      format          An enum value that contains the RSA private key format @n
74          *                                                      The valid values for the supported output RSA private key formats are only 
75          *                                                      @c RSA_KEY_FORMAT_PKCS01_PRIVATE_KEY and @c RSA_KEY_FORMAT_PKCS08_PRIVATE_KEY.
76          *      @param[in]      key                     An instance of IPrivateKey
77          *      @exception      E_SUCCESS               The method is successful.
78          *      @exception      E_INVALID_ARG   A specified input parameter is invalid.
79          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
80          */
81         static Tizen::Base::ByteBuffer* ConvertPrivateKeyFormatN(RsaKeyFormat format, const IPrivateKey& key);
82
83         /**
84          *      Generates an RSA encoded public key in the passed input RSA key format. @n
85          *      If the input public key is in PEM encoded format, then the output RSA public key will be PEM encoded; if it is in DER encoded format,
86          *      then the output RSA public key will be DER encoded.
87          *
88          *      @since          2.1
89          *
90          *      @return         A pointer to the encoded Tizen::Base::ByteBuffer instance, @n
91          *                              else @c null if the method fails to convert the public key in the passed input format
92          *      @param[in]      format                  An enum value that contains the RSA public key format @n
93          *                                                              The valid values for the supported output RSA public key formats are only 
94          *                                                              @c RSA_KEY_FORMAT_PKCS01_PUBLIC_KEY and @c RSA_KEY_FORMAT_X509_PUBLIC_KEY.
95          *      @param[in]      key                             An instance of IPublicKey
96          *      @exception      E_SUCCESS               The method is successful.
97          *      @exception      E_INVALID_ARG   A specified input parameter is invalid.
98          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
99          */
100         static Tizen::Base::ByteBuffer* ConvertPublicKeyFormatN(RsaKeyFormat format, const IPublicKey& key);
101
102         /**
103          *      Converts a DER encoded RSA key to the PEM encoded format.
104          *
105          *      @since          2.1
106          *
107          *      @return         A pointer to the PEM encoded Tizen::Base::ByteBuffer instance, @n
108          *                              else @c null if the method fails to convert the key in the PEM encoded format
109          *      @param[in]      format                  An enum value that contains the RSA key format of the input key
110          *      @param[in]      key                             An instance of IKey
111          *      @exception      E_SUCCESS               The method is successful.
112          *      @exception      E_INVALID_ARG   A specified input parameter is invalid.
113          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
114          */
115         static Tizen::Base::ByteBuffer* ConvertDerToPemN(RsaKeyFormat format, const IKey& key);
116
117         /**
118          *      Converts a PEM encoded RSA key to the DER encoded format.
119          *
120          *      @since          2.1
121          *
122          *      @return         A pointer to the DER encoded Tizen::Base::ByteBuffer instance, @n
123          *                              else @c null if the method fails to convert the key in the DER encoded format
124          *      @param[in]      format                          An enum value that contains the RSA key format of the input key
125          *      @param[in]      key                                     An instance of IKey
126          *      @exception      E_SUCCESS                       The method is successful.
127          *      @exception      E_INVALID_ARG           A specified input parameter is invalid.
128          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
129          */
130         static Tizen::Base::ByteBuffer* ConvertPemToDerN(RsaKeyFormat format, const IKey& key);
131
132 private:
133         //
134         // This default constructor is intentionally declared as private because this class cannot be constructed.
135         //
136         // @since       2.1
137         //
138         RsaKeyConverter(void);
139
140         //
141         // This destructor is intentionally declared as private because this class cannot be constructed.
142         //
143         // @since       2.1
144         //
145         ~RsaKeyConverter(void);
146
147         //
148         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
149         //
150         // @since 2.1
151         //
152         RsaKeyConverter(const RsaKeyConverter& rhs);
153
154         //
155         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
156         //
157         // @since 2.1
158         //
159         RsaKeyConverter& operator =(const RsaKeyConverter& rhs);
160
161 private:
162         class _RsaKeyConverterImpl* __pRsaKeyConverterImpl;
163         friend class _RsaKeyConverterImpl;
164
165 }; //RsaKeyConverter
166
167 } } //Tizen::Security
168
169 #endif // _FSEC_RSA_KEY_CONVERTER_H_