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 FSecSecretKeyGenerator.h
20 * @brief This is the header file for the %SecretKeyGenerator class.
22 * This header file contains the declarations of the %SecretKeyGenerator class.
24 #ifndef _FSEC_SECRET_KEY_GENERATOR_H_
25 #define _FSEC_SECRET_KEY_GENERATOR_H_
27 #include <FSecISecretKeyGenerator.h>
28 #include <FSecISecureRandom.h>
29 #include <FSecISecretKey.h>
32 namespace Tizen { namespace Security
36 * @class SecretKeyGenerator
37 * @brief This class is used for generating a secret (symmetric) key.
41 * The %SecretKeyGenerator class generates a secret key, which is used in symmetric ciphers. The generated secret key is based on an encryption algorithm. @n
43 * 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>.
45 * @see ISecretKeyGenerator
47 class _OSP_EXPORT_ SecretKeyGenerator
48 : public virtual ISecretKeyGenerator
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 SecretKeyGenerator(void);
62 * This destructor overrides Tizen::Base::Object::~Object().
66 virtual ~SecretKeyGenerator(void);
69 * Constructs and initializes this instance of %SecretKeyGenerator with the specified key.
73 * @return An error code
74 * @param[in] keyBytes The key of type Tizen::Base::ByteBuffer
75 * @exception E_SUCCESS The method is successful.
76 * @exception E_INVALID_ARG The specified @c keyBytes is invalid or an empty Tizen::Base::ByteBuffer.
77 * @exception E_OUT_OF_MEMORY The memory is insufficient.
79 result Construct(const Tizen::Base::ByteBuffer& keyBytes);
82 * Constructs and initializes this instance of %SecretKeyGenerator for the specified algorithm.
86 * @return An error code
87 * @param[in] algorithm The name of the secure random generator algorithm @n
88 * For example, "AES","DES" or "3DES".
89 * @exception E_SUCCESS The method is successful.
90 * @exception E_INVALID_ARG The specified @c algorithm is invalid or an empty string.
91 * @exception E_OUT_OF_MEMORY The memory is insufficient.
93 result Construct(const Tizen::Base::String& algorithm);
96 * Constructs and initializes this instance of %SecretKeyGenerator with the specified key size. @n
97 * The default algorithm is Advanced Encryption Standard (AES).
101 * @return An error code
102 * @param[in] keySize The key size
103 * @exception E_SUCCESS The method is successful.
104 * @exception E_INVALID_ARG The specified @c keySize is @c 0 or negative.
105 * @exception E_OUT_OF_MEMORY The memory is insufficient.
107 result Construct(int keySize);
110 * Generates a new secret key.
114 * @return A pointer to the ISecretKey interface, @n
115 * else @c null if it fails to generate a secret key
116 * @exception E_SUCCESS The method is successful.
117 * @exception E_OUT_OF_MEMORY The memory is insufficient.
118 * @exception E_SYSTEM A system error has occurred.
119 * @remarks The specific error code can be accessed using the GetLastResult() method.
121 virtual Tizen::Security::ISecretKey* GenerateKeyN(void);
126 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
130 SecretKeyGenerator(const SecretKeyGenerator& rhs);
133 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
137 SecretKeyGenerator& operator =(const SecretKeyGenerator& rhs);
140 Tizen::Base::String __algorithm;
142 Tizen::Security::ISecureRandom* __pRandom;
143 Tizen::Base::ByteBuffer __keyBytes;
145 class _SecretKeyGeneratorImpl* __pSecretKeyGeneratorImpl;
146 friend class _SecretKeyGeneratorImpl;
148 }; //SecretKeyGenerator
150 } } //Tizen::Security
152 #endif // _FSEC_SECRET_KEY_GENERATOR_H_