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 an asymmetric private key for signature.
76 * @return An error code
77 * @param[in] key An instance of IKey.
78 * 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 verification.
90 * @return An error code
91 * @param[in] key An instance of IKey
92 * 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 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_KEY_NOT_FOUND The specified key is not found.
111 * @exception E_SYSTEM A system error has occurred. @n
112 * The method has failed to operate with the OpenSSL library, or
113 * the Tizen::Base::ByteBuffer operation has failed.
114 * @remarks The specific error code can be accessed using the GetLastResult() method.
116 virtual Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input);
120 * The %SignN() method provides the additional option to developer for setting digest algorithm that is needed for signing the data
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 * @param[in] algorithm An instance of Tizen::Base::String that contains the digest algorithm,
128 * valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
129 * @exception E_SUCCESS The method is successful.
130 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
131 * @exception E_OUT_OF_MEMORY The memory is insufficient.
132 * @exception E_KEY_NOT_FOUND The specified key is not found.
133 * @exception E_UNSUPPORTED_ALGORITHM The specified algorithm is not supported.
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 Tizen::Base::ByteBuffer* SignN(const Tizen::Base::ByteBuffer& input, const Tizen::Base::String& algorithm);
142 * Verifies the data. @n
143 * The verification is done by comparing the @c signedData to the signature created by the @c data. @
144 * The %Verify() method only supports sha1withRsa for verifying the signed data
148 * @return @c true if the signed data is correct, @n
150 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
151 * @param[in] signedData A instance of Tizen::Base::ByteBuffer that contains the signed data
152 * @exception E_SUCCESS The method is successful.
153 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
154 * @exception E_OUT_OF_MEMORY The memory is insufficient.
155 * @exception E_KEY_NOT_FOUND The specified key is not found.
156 * @exception E_SYSTEM A system error has occurred. @n
157 * The method has failed to operate with the OpenSSL library, or
158 * the Tizen::Base::ByteBuffer operation has failed.
159 * @remarks The specific error code can be accessed using the GetLastResult() method.
161 virtual bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData);
164 * Verifies the data. @n
165 * The verification is done by comparing the @c signedData to the signature created by the @c data. @n
166 * The %Verify() method provides the additional option to developer for setting digest algorithm that is needed for verifying the signed data
170 * @return @c true if the signed data is correct, @n
172 * @param[in] data An instance of Tizen::Base::ByteBuffer that contains the original data
173 * @param[in] signedData A instance of Tizen::Base::ByteBuffer that contains the signed data
174 * @param[in] algorithm An instance of Tizen::Base::String that contains the digest algorithm,
175 * valid values are MD5, MD5WITHSHA1, SHA1, SHA2/224, SHA2/256, SHA2/384, SHA2/512.
176 * @exception E_SUCCESS The method is successful.
177 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
178 * @exception E_OUT_OF_MEMORY The memory is insufficient.
179 * @exception E_KEY_NOT_FOUND The specified key is not found.
180 * @exception E_UNSUPPORTED_ALGORITHM The specified algorithm is not supported.
181 * @exception E_SYSTEM A system error has occurred. @n
182 * The method has failed to operate with the OpenSSL library, or
183 * the Tizen::Base::ByteBuffer operation has failed.
184 * @remarks The specific error code can be accessed using the GetLastResult() method.
186 bool Verify(const Tizen::Base::ByteBuffer& data, const Tizen::Base::ByteBuffer& signedData, const Tizen::Base::String& algorithm);
191 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
195 RsaSignature(const RsaSignature& rhs);
198 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
202 RsaSignature& operator =(const RsaSignature& rhs);
205 Tizen::Base::ByteBuffer __privateKey;
206 Tizen::Base::ByteBuffer __publicKey;
208 class _RsaSignatureImpl* __pRsaSignatureImpl;
209 friend class _RsaSignatureImpl;
213 } } } //Tizen::Security::Crypto
215 #endif //_FSEC_CRYPTO_RSA_SIGNATURE_H_