2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSecRsaKeyConverter.h
19 * @brief This is the header file for the %RsaKeyConverter class.
21 * This header file contains the declarations of the %RsaKeyConverter class.
24 #ifndef _FSEC_RSA_KEY_CONVERTER_H_
25 #define _FSEC_RSA_KEY_CONVERTER_H_
27 #include <FSecIPublicKey.h>
28 #include <FSecIPrivateKey.h>
30 namespace Tizen { namespace Security
36 * Defines the types of rsa key format.
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 */
50 * @class RsaKeyConverter
51 * @brief This class provides support for converting the RSA public/private key in multiple key formats and multiple encoding formats.
55 * The %RsaKeyConverter class provides support for converting the RSA public/private key in multiple key formats and multiple encoding formats. @n
56 * Supported RSA key formats are PKCS1/PKCS8/X509. @n
57 * Supported encoding formats are DER/PEM.
60 class _OSP_EXPORT_ RsaKeyConverter
65 * Generates a 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.
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 * Valid values for the supported output RSA private key formats are only @c RSA_KEY_FORMAT_PKCS01_PRIVATE_KEY and @c RSA_KEY_FORMAT_PKCS08_PRIVATE_KEY.
75 * @param[in] key An instance of IPrivateKey
76 * @exception E_SUCCESS The method is successful.
77 * @exception E_INVALID_ARG A specified input parameter is invalid.
78 * @remarks The specific error code can be accessed using the GetLastResult() method.
80 static Tizen::Base::ByteBuffer* ConvertPrivateKeyFormatN(RsaKeyFormat format, const IPrivateKey& key);
83 * Generates a RSA encoded public key in the passed input RSA key format. @n
84 * 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,
85 * then the output RSA public key will be DER encoded.
89 * @return A pointer to the encoded Tizen::Base::ByteBuffer instance, @n
90 * else @c null if the method fails to convert the public key in the passed input format
91 * @param[in] format An enum value that contains the RSA public key format @n
92 * Valid values for the supported output RSA public key formats are only @c RSA_KEY_FORMAT_PKCS01_PUBLIC_KEY and @c RSA_KEY_FORMAT_X509_PUBLIC_KEY.
93 * @param[in] key An instance of IPublicKey
94 * @exception E_SUCCESS The method is successful.
95 * @exception E_INVALID_ARG A specified input parameter is invalid.
96 * @remarks The specific error code can be accessed using the GetLastResult() method.
98 static Tizen::Base::ByteBuffer* ConvertPublicKeyFormatN(RsaKeyFormat format, const IPublicKey& key);
101 * Converts a DER encoded RSA key to the PEM encoded format.
105 * @return A pointer to the PEM encoded Tizen::Base::ByteBuffer instance, @n
106 * else @c null if the method fails to convert the key in the PEM encoded format
107 * @param[in] format An enum value that contains the RSA key format of the input key
108 * @param[in] key An instance of IKey
109 * @exception E_SUCCESS The method is successful.
110 * @exception E_INVALID_ARG A specified input parameter is invalid.
111 * @remarks The specific error code can be accessed using the GetLastResult() method.
113 static Tizen::Base::ByteBuffer* ConvertDerToPemN(RsaKeyFormat format, const IKey& key);
116 * Converts a PEM encoded RSA key to the DER encoded format.
120 * @return A pointer to the DER encoded Tizen::Base::ByteBuffer instance, @n
121 * else @c null if the method fails to convert the key in the DER encoded format
122 * @param[in] format An enum value that contains the RSA key format of the input key
123 * @param[in] key An instance of IKey
124 * @exception E_SUCCESS The method is successful.
125 * @exception E_INVALID_ARG A specified input parameter is invalid.
126 * @remarks The specific error code can be accessed using the GetLastResult() method.
128 static Tizen::Base::ByteBuffer* ConvertPemToDerN(RsaKeyFormat format, const IKey& key);
132 // This default constructor is intentionally declared as private because this class cannot be constructed.
136 RsaKeyConverter(void);
139 // This destructor is intentionally declared as private because this class cannot be constructed.
143 ~RsaKeyConverter(void);
146 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
150 RsaKeyConverter(const RsaKeyConverter& rhs);
153 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
157 RsaKeyConverter& operator =(const RsaKeyConverter& rhs);
160 class _RsaKeyConverterImpl* __pRsaKeyConverterImpl;
161 friend class _RsaKeyConverterImpl;
165 } } //Tizen::Security
167 #endif // _FSEC_RSA_KEY_CONVERTER_H_