Module: Secure Communication Module Package: Secure Sockets
RWAsymmetricKeyRWHandleBase
#include <rw/secsock/RWAsymmetricKey.h>
RWAsymmetricKey encapsulates the underlying cryptographic library's representation of the asymmetric key. Public and private keys are identical in structure. Typedefs from RWAsymmetricKey to RWPublicKey and RWPrivateKey are provided.
RWAsymmetricKey uses the handle-body idiom to take over memory management from the cryptographic library.
The handle-body implementation of RWAsymmetricKey enables you to pass handles by value with the same cost as passing a class by pointer or reference. This implementation also ensures that the body and the associated memory are not destroyed until all handles referring to that body are destroyed.
RWAsymmetricKey's constructors throw an RWUnableToReadPrivateKeyError exception if the data is not in PEM format. They also throw RWSecureSocketNoCallbackSpecifiedError if your application passes an encrypted key, but does not name a password callback.
Other errors, including invalid key data, are detected only when the key is used in other functions. For this reason, you should validate keys by calling RWSecureSocketContext::checkPrivateKey() after assigning a certificate and private key to a context object.
NOTE -- For a full discussion of the handle-body idiom, see Section 7.3.1, "Understanding the Handle-Body Idiom," in the Threads Module User's Guide.
typedef RWAsymmetricKey RWPublicKey; typedef RWAsymmetricKey RWPrivateKey; extern "C" typedef int(*RWPasswordCallback)(char*, int, int); typedef EVP_PKEY* RWAsymmetricKeyRep;
RWAsymmetricKey(const char** pubKeyData, int numLines, RWPasswordCallback cb = 0);
Constructs a key from the data pointed to by pubKeyData. pubKeyData is a pointer to an array of C-style strings that contain the PEM-encoded key. Each line of a PEM-encoded key is an element in the array of strings.
numLines is the number of lines in the pubKeyData array. For example, if you are passing the pointer kData as the first parameter to this constructor, you should pass sizeof(kData)/sizeof(kData[0]) as the second parameter to this constructor.
If the key is encrypted, you must use cb to pass a callback function that provides the passphrase to the system. For more information, see the Secure Communication Module User's Guide.
This constructor throws RWSecureSocketUnderlyingAllocationError if the cryptographic library is unable to allocate memory. It throws RWSecureSocketNoCallbackSpecifiedError if your application passes an encrypted key, but does not name a password callback.
RWAsymmetricKey(istream& is, RWPasswordCallback cb = 0);
Constructs a key from PEM-format data in the istream. If the key is encrypted, you must use cb to pass a callback function that provides the passphrase to the system. For more information, see the Secure Communication Module User's Guide.
This constructor reads from the istream until an EOF is read. Instances of ifstream automatically end transmissions with an EOF. For example, if you pass an RWPortalIstream that ultimately reads from a socket, the stream only enters the EOF state when the sending socket is closed.
This constructor throws RWSecureSocketUnderlyingAllocationError if the cryptographic library is unable to allocate memory. It throws RWSecureSocketNoCallbackSpecifiedError if your application passes an encrypted key, but does not name a password callback.
RWAsymmetricKey(const RWAssymmetricKey& second);
Copy constructor.
~RWAsymmetricKey();
Destructor.
RWAsymmetricKey& operator=(const RWAsymmetricKey& second);
Assignment operator.
RWAsymmetricKeyRep getRep() const;
Returns a pointer to the cryptographic library's representation of the key.
NOTE -- The memory that the returned pointer references is owned by the body class, RWAsymmetricKeyImp, so users should not attempt to delete it. RWAsymmetricKeyImp deletes the memory when all handles referring to that body are destroyed.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.