Cloud is a computing paradigm for allowing data owners to outsource their data to enjoy on-demand services and mitigate the burden of local data storage. However, secure sharing of data via cloud remains an essential issue since the cloud service provider is untrusted. Fortunately, asymmetric-key encryption, such as identity-based encryption (IBE) and attribute-based encryption (ABE), provides a promising tool to offer data confidentiality and has been widely applied in cloud-based applications. In this paper, we summarize the common properties of most of IBE and ABE and introduce a cryptographic primitive called ElGamal type cryptosystem. This primitive can be used to derive a variety of ABE schemes. To illustrate the feasibility, we present generic constructions of revocable attribute-based encryption and dual-policy attribute-based encryption with formal definitions and security proofs. By applying our proposed generic constructions, we also present instantiations of these schemes. Furthermore, we demonstrate the high performance of the proposed schemes via experiments.