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 FSecCryptoRsaCipher.h
20 * @brief This is the header file for the %RsaCipher class.
22 * This header file contains the declarations of the %RsaCipher class.
24 #ifndef _FSEC_CRYPTO_RSA_CIPHER_H_
25 #define _FSEC_CRYPTO_RSA_CIPHER_H_
27 #include <FSecCryptoIAsymmetricCipher.h>
28 #include <FSecIPublicKey.h>
29 #include <FSecIPrivateKey.h>
33 namespace Tizen { namespace Security { namespace Crypto
38 * @brief This class provides methods for encryption and decryption using the Rivest Shamir Adleman (RSA) algorithm.
42 * The %RsaCipher class provides methods to encrypt and decrypt messages, and is used in the asymmetric cipher
45 * For more information on using the Rivest Shamir Adleman (RSA) algorithm for asymmetric ciphers, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
47 * @see Tizen::Security::KeyPair
48 * @see Tizen::Security::IPublicKey
49 * @see Tizen::Security::IPrivateKey
51 class _OSP_EXPORT_ RsaCipher
52 : public virtual IAsymmetricCipher
53 , public Tizen::Base::Object
58 * This is the default constructor for this class.
65 * This destructor overrides Tizen::Base::Object::~Object().
69 virtual ~RsaCipher(void);
72 * Sets an asymmetric private key for encryption or decryption.
76 * @return An error code
77 * @param[in] key An instance of IKey @n
78 * The @c key can be in PEM/DER/PKCS8 format only.
79 * @exception E_SUCCESS The method is successful.
80 * @exception E_INVALID_ARG The specified @c key is invalid.
81 * @exception E_OUT_OF_MEMORY The memory is insufficient.
83 virtual result SetPrivateKey(const Tizen::Security::IKey& key);
86 * Sets an asymmetric public key for encryption or decryption.
90 * @return An error code
91 * @param[in] key An instance of IKey
92 * The @c key can be in PEM/DER/X509 public key format only.
93 * @exception E_SUCCESS The method is successful.
94 * @exception E_INVALID_ARG The specified @c key is invalid.
95 * @exception E_OUT_OF_MEMORY The memory is insufficient.
97 virtual result SetPublicKey(const Tizen::Security::IKey& key);
100 * Encrypts the data (single-part).
104 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
105 * else @c null if an error occurs
106 * @param[in] input An instance of Tizen::Base::ByteBuffer
107 * @exception E_SUCCESS The method is successful.
108 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
109 * @exception E_OUT_OF_MEMORY The memory is insufficient.
110 * @exception E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
111 * @exception E_OVERFLOW This operation has caused the memory to overflow.
112 * @exception E_KEY_NOT_FOUND The specified key is not found.
113 * @exception E_SYSTEM A system error has occurred. @n
114 * The method has failed to operate with the OpenSSL library, or
115 * the Tizen::Base::ByteBuffer operation has failed.
116 * @remarks The specific error code can be accessed using the GetLastResult() method.
118 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
121 * Decrypts the data (single-part).
125 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
126 * else @c null if an error occurs
127 * @param[in] input An instance of Tizen::Base::ByteBuffer
128 * @exception E_SUCCESS The method is successful.
129 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
130 * @exception E_OUT_OF_MEMORY The memory is insufficient.
131 * @exception E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
132 * @exception E_OVERFLOW This operation has caused the memory to overflow.
133 * @exception E_KEY_NOT_FOUND The specified key is not found.
134 * @exception E_SYSTEM A system error has occurred. @n
135 * The method has failed to operate with the OpenSSL library, or
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* DecryptN(const Tizen::Base::ByteBuffer& input);
144 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
148 RsaCipher(const RsaCipher& rhs);
151 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
155 RsaCipher& operator =(const RsaCipher& rhs);
158 Tizen::Base::ByteBuffer __privateKey;
159 Tizen::Base::ByteBuffer __publicKey;
161 class _RsaCipherImpl* __pRsaCipherImpl;
162 friend class _RsaCipherImpl;
166 } } } //Tizen::Security::Crypto
168 #endif //_FSEC_CRYPTO_RSA_CIPHER_H_