Use dukgenerator instead of the _DeviceKeyGenerator for the PrivateKey encryption
[platform/framework/native/appfw.git] / inc / FSecKeyPairGenerator.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                        FSecKeyPairGenerator.h
20  * @brief               This is the header file for the %KeyPairGenerator class.
21  *
22  * This header file contains the declarations of the %KeyPairGenerator class.
23  */
24 #ifndef _FSEC_KEY_PAIR_GENERATOR_H_
25 #define _FSEC_KEY_PAIR_GENERATOR_H_
26
27 #include <FSecIKeyPairGenerator.h>
28 #include <FSecISecureRandom.h>
29 #include <FSecIKeyParameters.h>
30
31 namespace Tizen { namespace Security
32 {
33
34 /**
35  *  @class              KeyPairGenerator
36  *  @brief              This class provides a pair of public and private keys for the Public key algorithm.
37  *
38  *  @since  2.0
39  *
40  *  The %KeyPairGenerator class generates a key pair and its parameters that consists of a public and private key. These are used in asymmetric ciphers. The generated key pair and parameters are based on the underlying key pair encryption algorithm. @n
41  *
42  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/key_mgmt_and_csprng.htm">Key Management and CSPRNG</a>.
43  *
44  *  @see Tizen::Security::IKeyPairGenerator
45  *  @see Tizen::Security::KeyPair
46  */
47 class _OSP_EXPORT_ KeyPairGenerator
48         : public virtual IKeyPairGenerator
49         , public Tizen::Base::Object
50 {
51
52 public:
53         /**
54          * The object is not fully constructed after this constructor is called. For full construction, @n
55          * the Construct() method must be called right after calling this constructor.
56          *
57          * @since               2.0
58          */
59         KeyPairGenerator(void);
60
61         /**
62          * This destructor overrides Tizen::Base::Object::~Object().
63          *
64          * @since               2.0
65          */
66         virtual ~KeyPairGenerator(void);
67
68         /**
69          *      Constructs and initializes an instance of %KeyPairGenerator with the specified parameter.
70          *
71          *      @since          2.0
72          *
73          *      @return         An error code
74          *      @param[in]      modulusBitSize  The modulus size in bits
75          *      @exception      E_SUCCESS                       The method is successful.
76          *      @exception      E_INVALID_ARG           The specified size is invalid. @n
77          *                                                      The modulus size must be at least greater than or equal to @c 1024 bits @n
78          *                                                      to generate cryptographically secure keys.
79          */
80         virtual result Construct(int modulusBitSize);
81
82         /**
83          *      Constructs and initializes an instance of %KeyPairGenerator with the specified parameters.
84          *
85          * @since               2.0
86          *
87          *      @return         An error code
88          *      @param[in]      modulusBitSize                  The modulus size in bits @n
89          *                                                                              This is used for key generation.
90          *  @param[in]  algorithm                               The algorithm used to generate the key parameters @n
91          *                                                                              The supported algorithms are RSA, DH, and KEA. The default value is RSA.
92          *      @exception      E_SUCCESS                               The method is successful.
93          *      @exception      E_INVALID_ARG                   The specified size is invalid. @n
94          *      @exception      E_UNSUPPORTED_ALGORITHM The requested @c algorithm is not supported. @n
95          *                                                      The modulus size must be at least greater than or equal to @c 1024 bits @n
96          *                                                      to generate cryptographically secure keys.
97          */
98         result Construct(int modulusBitSize, const Tizen::Base::String algorithm);
99
100         /**
101          *      Generates the key parameters based on the underlying key pair algorithm. @n
102          *      For example, in case of the DH or KEA algorithm, this method generates key parameters based on the DSA
103          *      algorithm (X186.3 specification).
104          *      The supported algorithms are RSA, DH, and KEA.
105          *      The generated key parameters may be required to create a key pair. The RSA algorithm
106          *      does not call this method to generate a key pair.
107          *
108          *      @since                  2.0
109          *
110          *      @return                 A pointer to the IKeyParameters class that contains a subset of the domain parameters ('p' prime
111          *                                      number, 'g' generator) that are used to generate a key pair, @n
112          *                                      else @c null if the method fails to create the key parameters
113          *      @param[in]      lInBits         The size of 'p', a prime number in bits @n
114          *                                                      The size must be @c 1024 bits, @c 2048 bits, or @c 3072 bits.
115          *      @param[in]      nInBits         The size of 'g', a generator value in bits @n
116          *                                                      The size must be:
117          *                                                      - 160 bits, when @c lInBits is @c 1024 bits.
118          *                                                      - 254 or 256 bits, when @c lInBits is @c 2048 bits.
119          *                                                      - 256 bits, when @c lInBits is @c 3072 bits.
120          *      @exception      E_SUCCESS                                       The method is successful.
121          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
122          *      @exception      E_SYSTEM                                        The method cannot proceed due to a severe system error. @n
123          *                                                                                      The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
124          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
125          */
126         Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
127
128         /**
129          *      Generates a new key pair.
130          *
131          *      @since          2.0
132          *
133          *      @return         A pointer to the KeyPair class, @n
134          *                              else @c null if the method fails to create the key pair
135          *      @param[in]   pKeyParams                         The domain parameters of the key exchange algorithm @n
136          *                                                                              These parameters are instantiated.
137          *      @exception      E_SUCCESS                               The method is successful.
138          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
139          *      @exception      E_SYSTEM                                The method cannot proceed due to a severe system error.@n
140          *                                                                              The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
141          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
142          */
143         Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
144
145         /**
146          *      Generates a new key pair.
147          *
148          *      @since          2.0
149          *
150          *      @return         A pointer to the KeyPair class, @n
151                         else @c null if the method fails to create the key pair.
152          *                              Default key format will be pkcs1 for private key and x509 for public key.
153          *      @exception      E_SUCCESS                                       The method is successful.
154          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
155          *      @exception      E_SYSTEM                                        The method cannot proceed due to a severe system error. @n
156          *                                                                                      The method has failed to operate with the OpenSSL library, or the Tizen::Base::ByteBuffer operation has failed.
157          * @remarks     The specific error code can be accessed using the GetLastResult() method.
158          */
159         virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
160
161 private:
162         //
163         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
164         //
165         // @since 2.0
166         //
167         KeyPairGenerator(const KeyPairGenerator& rhs);
168
169         //
170         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
171         //
172         // @since 2.0
173         //
174         KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
175
176 private:
177         Tizen::Base::String __algorithm;
178         int __modulusBitSize;
179
180         class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
181         friend class _KeyPairGeneratorImpl;
182
183 };     //KeyPairGenerator
184
185 } } //Tizen::Security
186
187 #endif // _FSEC_KEY_PAIR_GENERATOR_H_