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 FSecCryptoRsaCipher.h
19 * @brief This is the header file for the %RsaCipher class.
21 * This header file contains the declarations of the %RsaCipher class.
23 #ifndef _FSEC_CRYPTO_RSA_CIPHER_H_
24 #define _FSEC_CRYPTO_RSA_CIPHER_H_
26 #include <FSecCryptoIAsymmetricCipher.h>
27 #include <FSecIPublicKey.h>
28 #include <FSecIPrivateKey.h>
32 namespace Tizen { namespace Security { namespace Crypto
37 * @brief This class provides methods for encryption and decryption using the Rivest Shamir Adleman (RSA) algorithm.
41 * The %RsaCipher class provides methods to encrypt and decrypt messages, and is used in the asymmetric cipher
44 * 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>.
46 * @see Tizen::Security::KeyPair
47 * @see Tizen::Security::IPublicKey
48 * @see Tizen::Security::IPrivateKey
50 class _OSP_EXPORT_ RsaCipher
51 : public virtual IAsymmetricCipher
52 , public Tizen::Base::Object
57 * This is the default constructor for this class.
64 * This destructor overrides Tizen::Base::Object::~Object().
68 virtual ~RsaCipher(void);
71 * Sets an asymmetric private key for encryption or decryption.
75 * @return An error code
76 * @param[in] key An instance of IKey @n
77 * The @c key can be in PEM/DER/PKCS8 format only.
78 * @exception E_SUCCESS The method is successful.
79 * @exception E_INVALID_ARG The specified @c key is invalid.
80 * @exception E_OUT_OF_MEMORY The memory is insufficient.
82 virtual result SetPrivateKey(const Tizen::Security::IKey& key);
85 * Sets an asymmetric public key for encryption or decryption.
89 * @return An error code
90 * @param[in] key An instance of IKey
91 * The @c key can be in PEM/DER/X509 public key format only.
92 * @exception E_SUCCESS The method is successful.
93 * @exception E_INVALID_ARG The specified @c key is invalid.
94 * @exception E_OUT_OF_MEMORY The memory is insufficient.
96 virtual result SetPublicKey(const Tizen::Security::IKey& key);
99 * Encrypts the data (single-part).
103 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
104 * else @c null if an error occurs
105 * @param[in] input An instance of Tizen::Base::ByteBuffer
106 * @exception E_SUCCESS The method is successful.
107 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
108 * @exception E_OUT_OF_MEMORY The memory is insufficient.
109 * @exception E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
110 * @exception E_OVERFLOW This operation has caused the memory to overflow.
111 * @exception E_KEY_NOT_FOUND The specified key is not found.
112 * @exception E_SYSTEM A system error has occurred. @n
113 * The method has failed to operate with the OpenSSL library, or
114 * the Tizen::Base::ByteBuffer operation has failed.
115 * @remarks The specific error code can be accessed using the GetLastResult() method.
117 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
120 * Decrypts the data (single-part).
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 input Tizen::Base::ByteBuffer is empty or contains invalid data.
129 * @exception E_OUT_OF_MEMORY The memory is insufficient.
130 * @exception E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
131 * @exception E_OVERFLOW This operation has caused the memory to overflow.
132 * @exception E_KEY_NOT_FOUND The specified key is not found.
133 * @exception E_SYSTEM A system error has occurred. @n
134 * The method has failed to operate with the OpenSSL library, or
135 * the Tizen::Base::ByteBuffer operation has failed.
136 * @remarks The specific error code can be accessed using the GetLastResult() method.
138 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
143 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
147 RsaCipher(const RsaCipher& rhs);
150 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
154 RsaCipher& operator =(const RsaCipher& rhs);
157 Tizen::Base::ByteBuffer __privateKey;
158 Tizen::Base::ByteBuffer __publicKey;
160 class _RsaCipherImpl* __pRsaCipherImpl;
161 friend class _RsaCipherImpl;
165 } } } //Tizen::Security::Crypto
167 #endif //_FSEC_CRYPTO_RSA_CIPHER_H_