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 FSecCryptoRsaSignature.h
19 * @brief This is the header file for the %RsaSignature class.
21 * This header file contains the declarations of the %RsaSignature class.
23 #ifndef _FSEC_CRYPTO_RSA_SIGNATURE_H_
24 #define _FSEC_CRYPTO_RSA_SIGNATURE_H_
26 #include <FSecCryptoISignature.h>
30 namespace Tizen { namespace Security { namespace Crypto
35 * @brief This class implements the Rivest Shamir Adleman (RSA) signatures.
39 * The %RsaSignature class implements the Rivest Shamir Adleman (RSA) signatures. @n
41 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
44 * @see IKeyPairGenerator
51 class _OSP_EXPORT_ RsaSignature
52 : public virtual ISignature
53 , public Tizen::Base::Object
58 * This is the default constructor for this class.
65 * This destructor overrides Tizen::Base::Object::~Object().
69 virtual ~RsaSignature(void);
72 * Sets the asymmetric private key for signature.
76 * @return An error code
77 * @param[in] key An instance of IKey
78 * The 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 the asymmetric public key for verification.
90 * @return An error code
91 * @param[in] key An instance of IKey
92 * The 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);
101 * The %SignN() method only supports sha1withRsa for signing the data
104 * @return A pointer to the Tizen::Base::ByteBuffer instance 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_KEY_NOT_FOUND The specified key is not found.
111 * @exception E_SYSTEM Either of the following conditions has occurred:
112 * - A system error has occurred.
113 * - The method has failed to operate with the OpenSSL library.
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* SignN(const Tizen::Base::ByteBuffer& input);
121 * The %SignN() method provides the additional option for setting the digest algorithm that is needed for signing the data
125 * @return A pointer to the Tizen::Base::ByteBuffer instance that contains the output, @n
126 * else @c null if an error occurs
127 * @param[in] input An instance of Tizen::Base::ByteBuffer
128 * @param[in] algorithm The Tizen::Base::String instance that contains the digest algorithm. @n
129 * The valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
130 * @exception E_SUCCESS The method is successful.
131 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
132 * @exception E_OUT_OF_MEMORY The memory is insufficient.
133 * @exception E_KEY_NOT_FOUND The specified key is not found.
134 * @exception E_UNSUPPORTED_ALGORITHM The specified algorithm is not supported.
135 * @exception E_SYSTEM Either of the following conditions has occurred:
136 * - A system error has occurred.
137 * - The method has failed to operate with the OpenSSL library.
138 * - The Tizen::Base::ByteBuffer operation has failed.
139 * @remarks The specific error code can be accessed using the GetLastResult() method.
141 Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input, const Tizen::Base::String& algorithm);
144 * Verifies the data. @n
145 * The verification is done by comparing the @c signedData to the signature created by the @c data. @
146 * The %Verify() method only supports sha1withRsa for verifying the signed data
150 * @return @c true if the signed data is correct, @n
152 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
153 * @param[in] signedData An instance of Tizen::Base::ByteBuffer that contains the signed data
154 * @exception E_SUCCESS The method is successful.
155 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
156 * @exception E_OUT_OF_MEMORY The memory is insufficient.
157 * @exception E_KEY_NOT_FOUND The specified key is not found.
158 * @exception E_SYSTEM Either of the following conditions has occurred:
159 * - A system error has occurred.
160 * - The method has failed to operate with the OpenSSL library.
161 * - The Tizen::Base::ByteBuffer operation has failed.
162 * @remarks The specific error code can be accessed using the GetLastResult() method.
164 virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData);
167 * Verifies the data. @n
168 * The verification is done by comparing the @c signedData to the signature created by the @c data. @n
169 * The %Verify() method provides the additional option for setting the digest algorithm that is needed for verifying the signed data
173 * @return @c true if the signed data is correct, @n
175 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
176 * @param[in] signedData An instance of Tizen::Base::ByteBuffer that contains the signed data
177 * @param[in] algorithm The Tizen::Base::String instance that contains the digest algorithm. @n
178 * The valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
181 * @exception E_OUT_OF_MEMORY The memory is insufficient.
182 * @exception E_KEY_NOT_FOUND The specified key is not found.
183 * @exception E_UNSUPPORTED_ALGORITHM The specified algorithm is not supported.
184 * @exception E_SYSTEM Either of the following conditions has occurred:
185 * - A system error has occurred.
186 * - The method has failed to operate with the OpenSSL library.
187 * - The Tizen::Base::ByteBuffer operation has failed.
188 * @remarks The specific error code can be accessed using the GetLastResult() method.
190 bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData, const Tizen::Base::String& algorithm);
195 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
199 RsaSignature(const RsaSignature& rhs);
202 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
206 RsaSignature& operator =(const RsaSignature& rhs);
209 Tizen::Base::ByteBuffer __privateKey;
210 Tizen::Base::ByteBuffer __publicKey;
212 class _RsaSignatureImpl* __pRsaSignatureImpl;
213 friend class _RsaSignatureImpl;
217 } } } //Tizen::Security::Crypto
219 #endif //_FSEC_CRYPTO_RSA_SIGNATURE_H_