2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FSecKeyPairGenerator.h
20 * @brief This is the header file for the %KeyPairGenerator class.
22 * This header file contains the declarations of the %KeyPairGenerator class.
24 #ifndef _FSEC_KEY_PAIR_GENERATOR_H_
25 #define _FSEC_KEY_PAIR_GENERATOR_H_
27 #include <FSecIKeyPairGenerator.h>
28 #include <FSecISecureRandom.h>
29 #include <FSecIKeyParameters.h>
31 namespace Tizen { namespace Security
35 * @class KeyPairGenerator
36 * @brief This class provides a pair of public and private keys for the Public key algorithm.
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
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>.
44 * @see Tizen::Security::IKeyPairGenerator
45 * @see Tizen::Security::KeyPair
47 class _OSP_EXPORT_ KeyPairGenerator
48 : public virtual IKeyPairGenerator
49 , public Tizen::Base::Object
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.
59 KeyPairGenerator(void);
62 * This destructor overrides Tizen::Base::Object::~Object().
66 virtual ~KeyPairGenerator(void);
69 * Constructs and initializes an instance of %KeyPairGenerator with the specified parameter.
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.
80 virtual result Construct(int modulusBitSize);
83 * Constructs and initializes an instance of %KeyPairGenerator with the specified parameters.
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.
98 result Construct(int modulusBitSize, const Tizen::Base::String algorithm);
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.
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
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.
126 Tizen::Security::IKeyParameters* GenerateKeyParametersN(int lInBits = 1024, int nInBits = 160) const;
129 * Generates a new key pair.
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.
143 Tizen::Security::KeyPair* GenerateKeyPairN(Tizen::Security::IKeyParameters* pKeyParams) const;
146 * Generates a new key pair.
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.
159 virtual Tizen::Security::KeyPair* GenerateKeyPairN(void) const;
163 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
167 KeyPairGenerator(const KeyPairGenerator& rhs);
170 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
174 KeyPairGenerator& operator =(const KeyPairGenerator& rhs);
177 Tizen::Base::String __algorithm;
178 int __modulusBitSize;
180 class _KeyPairGeneratorImpl* __pKeyPairGeneratorImpl;
181 friend class _KeyPairGeneratorImpl;
183 }; //KeyPairGenerator
185 } } //Tizen::Security
187 #endif // _FSEC_KEY_PAIR_GENERATOR_H_