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 FSecCryptoDesCipher.h
19 * @brief This is the header file for the %DesCipher class.
21 * This header file contains the declarations of the %DesCipher class.
23 #ifndef _FSEC_CRYPTO_DES_CIPHER_H_
24 #define _FSEC_CRYPTO_DES_CIPHER_H_
26 #include <FSecCryptoISymmetricCipher.h>
31 namespace Tizen { namespace Security { namespace Crypto
34 class _SymmetricCipher;
37 * @brief This class provides methods for encryption and decryption using the Data Encryption Standard (DES) method.
41 * The %DesCipher class provides a symmetric cipher using the Data Encryption Standard (DES) method.
42 * This class allows to set appropriate values for the requested mode/key bit/padding scheme and cipher operation mode
43 * (::CIPHER_ENCRYPT or ::CIPHER_DECRYPT) parameters. @n
45 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
47 * @see ISymmetricCipher
51 class _OSP_EXPORT_ DesCipher
52 : public virtual ISymmetricCipher
53 , public Tizen::Base::Object
58 * The object is not fully constructed after this constructor is called. For full construction, @n
59 * the Construct() method must be called right after calling this constructor.
66 * This destructor overrides Tizen::Base::Object::~Object().
70 virtual ~DesCipher(void);
73 * Initializes this instance of %DesCipher with the specified parameters.
77 * @return An error code
78 * @param[in] transformation The requested mode/key bit/padding scheme @n
79 * For example, "CBC/NOPADDING" or "CBC/PKCS7PADDING".
80 * @param[in] opMode The cipher operation mode @n
81 * The valid values for %DesCipher are @c CIPHER_ENCRYPT and @c CIPHER_DECRYPT.
82 * @exception E_SUCCESS The method is successful.
83 * @exception E_OUT_OF_MEMORY The memory is insufficient.
84 * @exception E_INVALID_ARG Either of the following conditions has occurred:
85 * - A specified input parameter is invalid.
86 * - The specified @c opMode does not contain a valid value for the cipher operation.
87 * @remarks If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
88 * For example, if @c opMode is set to @c CIPHER_ENCRYPT, @c CIPHER_WRAP, or @c CIPHER_UNWRAP and the DecryptN()
89 * method is used, then the result obtained is @c null and an exception is returned.
91 virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
94 * Sets the symmetric key for encryption or decryption.
98 * @return An error code
99 * @param[in] key An instance of ISecretKey
100 * @exception E_SUCCESS The method is successful.
101 * @exception E_INVALID_ARG The specified @c key is invalid.
102 * @exception E_OUT_OF_MEMORY The memory is insufficient.
104 virtual result SetKey(const Tizen::Security::ISecretKey& key);
107 * Sets the initial vector.
111 * @return An error code
112 * @param[in] initialVector The initial vector
113 * @exception E_SUCCESS The method is successful.
114 * @exception E_INVALID_ARG The specified input parameter is invalid.
115 * @exception E_OUT_OF_MEMORY The memory is insufficient.
117 virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
120 * Encrypts the data (single-part).
123 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
124 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
125 * else @c null if an error occurs
126 * @param[in] input An instance of Tizen::Base::ByteBuffer
127 * @exception E_SUCCESS The method is successful.
128 * @exception E_INVALID_ARG The specified Tizen::Base::ByteBuffer instance is invalid or empty.
129 * @exception E_OUT_OF_MEMORY The memory is insufficient.
130 * @exception E_KEY_NOT_FOUND The specified key is not found.
131 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
132 * @exception E_OVERFLOW This operation has caused the memory to overflow.
133 * @exception E_SYSTEM Either of the following conditions has occurred:
134 * - A system error has occurred.
135 * - The method has failed to operate with the OpenSSL library.
136 * - The Tizen::Base::ByteBuffer operation has failed.
137 * @remarks The specific error code can be accessed using the GetLastResult() method.
139 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
142 * Decrypts the data (single-part).
145 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
146 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
147 * else @c null if an error occurs
148 * @param[in] input An instance of Tizen::Base::ByteBuffer
149 * @exception E_SUCCESS The method is successful.
150 * @exception E_INVALID_ARG The specified Tizen::Base::ByteBuffer instance is invalid or empty.
151 * @exception E_OUT_OF_MEMORY The memory is insufficient.
152 * @exception E_KEY_NOT_FOUND The specified key is not found.
153 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
154 * @exception E_OVERFLOW This operation has caused the memory to overflow.
155 * @exception E_SYSTEM Either of the following conditions has occurred:
156 * - A system error has occurred.
157 * - The method has failed to operate with the OpenSSL library.
158 * - The Tizen::Base::ByteBuffer operation has failed.
159 * @remarks The specific error code can be accessed using the GetLastResult() method.
161 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
164 * Initializes the instance of %DesCipher for the multiple-part encryption or decryption.
167 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
168 * @return An error code
169 * @exception E_SUCCESS The method is successful.
170 * @exception E_OUT_OF_MEMORY The memory is insufficient.
171 * @exception E_KEY_NOT_FOUND The specified key is not found.
172 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
173 * @exception E_SYSTEM Either of the following conditions has occurred:
174 * - A system error has occurred.
175 * - The method has failed to operate with the openssl library.
177 virtual result Initialize(void);
180 * Updates the multiple-part encryption or decryption operation.
184 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
185 * else @c null if an error occurs
186 * @param[in] input An instance of Tizen::Base::ByteBuffer
187 * @exception E_SUCCESS The method is successful.
188 * @exception E_OUT_OF_MEMORY The memory is insufficient.
189 * @exception E_OVERFLOW This operation has caused the memory to overflow.
190 * @exception E_INVALID_ARG The specified Tizen::Base::ByteBuffer instance is invalid or empty.
191 * @exception E_SYSTEM Either of the following conditions has occurred:
192 * - A system error has occurred.
193 * - The method has failed to operate with the OpenSSL library.
194 * - The Tizen::Base::ByteBuffer operation has failed.
195 * @remarks The specific error code can be accessed using the GetLastResult() method.
197 virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
200 * Finalizes the multiple-part encryption or decryption operation.
204 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
205 * else @c null if an error occurs
206 * @exception E_SUCCESS The method is successful.
207 * @exception E_OUT_OF_MEMORY The memory is insufficient.
208 * @exception E_OVERFLOW This operation has caused the memory to overflow.
209 * @exception E_SYSTEM Either of the following conditions has occurred:
210 * - A system error has occurred
211 * - The method has failed to operate with the OpenSSL library.
212 * - The Tizen::Base::ByteBuffer operation has failed.
213 * @remarks The specific error code can be accessed using the GetLastResult() method.
215 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
222 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
223 * else @c null if an error occurs
224 * @param[in] secretKey The secret key to wrap
226 * - This operation is not supported in the %DesCipher class.
227 * Therefore, this method always returns @c null.
228 * - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
230 virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
233 * Unwraps a previously wrapped key.
237 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
238 * else @c null if an error occurs
239 * @param[in] wrappedKey The wrapped key to unwrap
241 * - This operation is not supported in the %DesCipher class.
242 * Therefore, this method always returns @c null.
243 * - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
245 virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
250 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
254 DesCipher(const DesCipher& rhs);
257 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
261 DesCipher& operator =(const DesCipher& rhs);
264 _SymmetricCipher* __pSymmetricCipher;
265 const evp_cipher_st* __pCipherAlgorithm;
266 Tizen::Base::String __cipherAlgorithm;
268 class _DesCipherImpl* __pDesCipherImpl;
269 friend class _DesCipherImpl;
273 } } } //Tizen::Security::Crypto
275 #endif //_FSEC_CRYPTO_DES_CIPHER_H_