2 // Copyright (c) 2012 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 FSecSecretKeyGenerator.h
19 * @brief This is the header file for the %SecretKeyGenerator class.
21 * This header file contains the declarations of the %SecretKeyGenerator class.
23 #ifndef _FSEC_SECRET_KEY_GENERATOR_H_
24 #define _FSEC_SECRET_KEY_GENERATOR_H_
26 #include <FSecISecretKeyGenerator.h>
27 #include <FSecISecureRandom.h>
28 #include <FSecISecretKey.h>
31 namespace Tizen { namespace Security
35 * @class SecretKeyGenerator
36 * @brief This class is used for generating a secret (symmetric) key.
40 * The %SecretKeyGenerator class generates a secret key, which is used in symmetric ciphers. The generated secret key is based on an 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 ISecretKeyGenerator
46 class _OSP_EXPORT_ SecretKeyGenerator
47 : public virtual ISecretKeyGenerator
48 , public Tizen::Base::Object
53 * The object is not fully constructed after this constructor is called. For full construction, @n
54 * the Construct() method must be called right after calling this constructor.
58 SecretKeyGenerator(void);
61 * This destructor overrides Tizen::Base::Object::~Object().
65 virtual ~SecretKeyGenerator(void);
68 * Constructs and initializes this instance of %SecretKeyGenerator with the specified key.
72 * @return An error code
73 * @param[in] keyBytes The key of type Tizen::Base::ByteBuffer
74 * @exception E_SUCCESS The method is successful.
75 * @exception E_INVALID_ARG The specified @c keyBytes is invalid or an empty Tizen::Base::ByteBuffer.
76 * @exception E_OUT_OF_MEMORY The memory is insufficient.
78 result Construct(const Tizen::Base::ByteBuffer& keyBytes);
81 * Constructs and initializes this instance of %SecretKeyGenerator for the specified @c algorithm.
85 * @return An error code
86 * @param[in] algorithm The name of the secure random generator algorithm @n
87 * For example, "AES","DES", or "3DES".
88 * @exception E_SUCCESS The method is successful.
89 * @exception E_INVALID_ARG The specified @c algorithm is invalid or an empty string.
90 * @exception E_OUT_OF_MEMORY The memory is insufficient.
92 result Construct(const Tizen::Base::String& algorithm);
95 * Constructs and initializes this instance of %SecretKeyGenerator with the specified key size. @n
96 * The default algorithm is Advanced Encryption Standard (AES).
100 * @return An error code
101 * @param[in] keySize The key size
102 * @exception E_SUCCESS The method is successful.
103 * @exception E_INVALID_ARG The specified @c keySize is @c 0 or negative.
104 * @exception E_OUT_OF_MEMORY The memory is insufficient.
106 result Construct(int keySize);
109 * Generates a new secret key.
113 * @return A pointer to the ISecretKey interface, @n
114 * else @c null if it fails to generate a secret key
115 * @exception E_SUCCESS The method is successful.
116 * @exception E_OUT_OF_MEMORY The memory is insufficient.
117 * @exception E_SYSTEM A system error has occurred.
118 * @remarks The specific error code can be accessed using the GetLastResult() method.
120 virtual Tizen::Security::ISecretKey* GenerateKeyN(void);
125 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
129 SecretKeyGenerator(const SecretKeyGenerator& rhs);
132 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
136 SecretKeyGenerator& operator =(const SecretKeyGenerator& rhs);
139 Tizen::Base::String __algorithm;
141 Tizen::Security::ISecureRandom* __pRandom;
142 Tizen::Base::ByteBuffer __keyBytes;
144 class _SecretKeyGeneratorImpl* __pSecretKeyGeneratorImpl;
145 friend class _SecretKeyGeneratorImpl;
147 }; //SecretKeyGenerator
149 } } //Tizen::Security
151 #endif // _FSEC_SECRET_KEY_GENERATOR_H_