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 FSecCryptoRsaSignature.h
20 * @brief This is the header file for the %RsaSignature class.
22 * This header file contains the declarations of the %RsaSignature class.
24 #ifndef _FSEC_CRYPTO_RSA_SIGNATURE_H_
25 #define _FSEC_CRYPTO_RSA_SIGNATURE_H_
27 #include <FSecCryptoISignature.h>
31 namespace Tizen { namespace Security { namespace Crypto
36 * @brief This class implements the Rivest Shamir Adleman (RSA) signatures.
40 * The %RsaSignature class implements the Rivest Shamir Adleman (RSA) signatures. @n
42 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
45 * @see IKeyPairGenerator
52 class _OSP_EXPORT_ RsaSignature
53 : public virtual ISignature
54 , public Tizen::Base::Object
59 * This is the default constructor for this class.
66 * This destructor overrides Tizen::Base::Object::~Object().
70 virtual ~RsaSignature(void);
73 * Sets an asymmetric private key for signature.
77 * @return An error code
78 * @param[in] key An instance of IKey.
79 * Key can be in PEM/DER/PKCS8 format only.
80 * @exception E_SUCCESS The method is successful.
81 * @exception E_INVALID_ARG The specified @c key is invalid.
82 * @exception E_OUT_OF_MEMORY The memory is insufficient.
84 virtual result SetPrivateKey(const Tizen::Security::IKey& key);
87 * Sets an asymmetric public key for verification.
91 * @return An error code
92 * @param[in] key An instance of IKey
93 * Key can be in PEM/DER/X509 public key format only.
94 * @exception E_SUCCESS The method is successful.
95 * @exception E_INVALID_ARG The specified @c key is invalid.
96 * @exception E_OUT_OF_MEMORY The memory is insufficient.
98 virtual result SetPublicKey(const Tizen::Security::IKey& key);
102 * The %SignN() method only supports sha1withRsa for signing the data
105 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
106 * else @c null if an error occurs
107 * @param[in] input An instance of Tizen::Base::ByteBuffer
108 * @exception E_SUCCESS The method is successful.
109 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
110 * @exception E_OUT_OF_MEMORY The memory is insufficient.
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* SignN(const Tizen::Base::ByteBuffer& input);
121 * The %SignN() method provides the additional option to developer for setting digest algorithm that is needed for signing the data
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 * @param[in] algorithm An instance of Tizen::Base::String that contains the digest algorithm,
129 * 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 A system error has occurred. @n
136 * The method has failed to operate with the OpenSSL library, or
137 * the Tizen::Base::ByteBuffer operation has failed.
138 * @remarks The specific error code can be accessed using the GetLastResult() method.
140 Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input, const Tizen::Base::String& algorithm);
143 * Verifies the data. @n
144 * The verification is done by comparing the @c signedData to the signature created by the @c data. @
145 * The %Verify() method only supports sha1withRsa for verifying the signed data
149 * @return @c true if the signed data is correct, @n
151 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
152 * @param[in] signedData A instance of Tizen::Base::ByteBuffer that contains the signed data
153 * @exception E_SUCCESS The method is successful.
154 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
155 * @exception E_OUT_OF_MEMORY The memory is insufficient.
156 * @exception E_KEY_NOT_FOUND The specified key is not found.
157 * @exception E_SYSTEM A system error has occurred. @n
158 * The method has failed to operate with the OpenSSL library, or
159 * the Tizen::Base::ByteBuffer operation has failed.
160 * @remarks The specific error code can be accessed using the GetLastResult() method.
162 virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData);
165 * Verifies the data. @n
166 * The verification is done by comparing the @c signedData to the signature created by the @c data. @n
167 * The %Verify() method provides the additional option to developer for setting digest algorithm that is needed for verifying the signed data
171 * @return @c true if the signed data is correct, @n
173 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
174 * @param[in] signedData A instance of Tizen::Base::ByteBuffer that contains the signed data
175 * @param[in] algorithm An instance of Tizen::Base::String that contains the digest algorithm,
176 * valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
177 * @exception E_SUCCESS The method is successful.
178 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
179 * @exception E_OUT_OF_MEMORY The memory is insufficient.
180 * @exception E_KEY_NOT_FOUND The specified key is not found.
181 * @exception E_UNSUPPORTED_ALGORITHM The specified algorithm is not supported.
182 * @exception E_SYSTEM A system error has occurred. @n
183 * The method has failed to operate with the OpenSSL library, or
184 * the Tizen::Base::ByteBuffer operation has failed.
185 * @remarks The specific error code can be accessed using the GetLastResult() method.
187 bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData, const Tizen::Base::String& algorithm);
192 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
196 RsaSignature(const RsaSignature& rhs);
199 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
203 RsaSignature& operator =(const RsaSignature& rhs);
206 Tizen::Base::ByteBuffer __privateKey;
207 Tizen::Base::ByteBuffer __publicKey;
209 class _RsaSignatureImpl* __pRsaSignatureImpl;
210 friend class _RsaSignatureImpl;
214 } } } //Tizen::Security::Crypto
216 #endif //_FSEC_CRYPTO_RSA_SIGNATURE_H_