1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Class Poco::Crypto::Cipher</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="author" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="publisher" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="copyright" content="Copyright (c) 2009, Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="language" content="en"/>
<meta name="date" content="2009-11-24"/>
<meta name="generator" content="PocoDoc"/>
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
<div class="header">
<h1 class="namespace"><a href="Poco.Crypto.html" class="namespace">Poco::Crypto</a></h1>
<h1 class="symbol">class Cipher</h1>
</div>
<div class="body">
<p>
<b>Library:</b> Crypto<br />
<b>Package:</b> Cipher<br />
<b>Header:</b> Poco/Crypto/Cipher.h</p>
<h2>Description</h2>
<div class="description">
<p>Represents the abstract base class from which all implementations of symmetric/assymetric encryption algorithms must inherit. Use the <a href="Poco.Crypto.CipherFactory.html" title="class Poco::Crypto::CipherFactory">CipherFactory</a> class to obtain an instance of this class: </p>
<p></p>
<pre>CipherFactory& factory = CipherFactory::defaultFactory();
// Creates a 256-bit AES cipher
Cipher* pCipher = factory.createCipher(CipherKey("aes-256"));
Cipher* pRSACipher = factory.createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
</pre>
<p>Check the different Key constructors on how to initialize/create a key. The above example auto-generates random keys. </p>
<p>Note that you won't be able to decrypt data encrypted with a random key once the <a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a> is destroyed unless you persist the generated key and IV. An example usage for random keys is to encrypt data saved in a temporary file. </p>
<p>Once your key is set up, you can use the <a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a> object to encrypt or decrypt strings or, in conjunction with a <a href="Poco.Crypto.CryptoInputStream.html" title="class Poco::Crypto::CryptoInputStream">CryptoInputStream</a> or a <a href="Poco.Crypto.CryptoOutputStream.html" title="class Poco::Crypto::CryptoOutputStream">CryptoOutputStream</a>, to encrypt streams of data. </p>
<p>Since encrypted strings will contain arbitary binary data that will cause problems in applications that are not binary-safe (eg., when sending encrypted data in e-mails), the <a href="Poco.Crypto.Cipher.html#14" title="Poco::Crypto::Cipher::encryptString()">encryptString</a>() and <a href="Poco.Crypto.Cipher.html#17" title="Poco::Crypto::Cipher::decryptString()">decryptString</a>() can encode (or decode, respectively) encrypted data using a "transport encoding". Supported encodings are Base64 and BinHex. </p>
<p>The following example encrypts and decrypts a string utilizing Base64 encoding: </p>
<p></p>
<pre>std::string plainText = "This is my secret information";
std::string encrypted = pCipher->encryptString(plainText, Cipher::ENC_BASE64);
std::string decrypted = pCipher->decryptString(encrypted, Cipher::ENC_BASE64);
</pre>
<p>In order to encrypt a stream of data (eg. to encrypt files), you can use a CryptoStream: </p>
<p></p>
<pre>// Create an output stream that will encrypt all data going through it
// and write pass it to the underlying file stream.
Poco::FileOutputStream sink("encrypted.dat");
CryptoOutputStream encryptor(sink, pCipher->createEncryptor());
Poco::FileInputStream source("source.txt");
Poco::StreamCopier::copyStream(source, encryptor);
// Always close output streams to flush all internal buffers
encryptor.close();
sink.close();
</pre>
</div>
<h2>Inheritance</h2>
<p><b>Direct Base Classes: </b><a href="Poco.RefCountedObject.html" title="class Poco::RefCountedObject">Poco::RefCountedObject</a></p>
<p><b>All Base Classes: </b><a href="Poco.RefCountedObject.html" title="class Poco::RefCountedObject">Poco::RefCountedObject</a></p>
<p><b>Known Derived Classes: </b><a href="Poco.Crypto.CipherImpl.html" title="class Poco::Crypto::CipherImpl">CipherImpl</a>, <a href="Poco.Crypto.RSACipherImpl.html" title="class Poco::Crypto::RSACipherImpl">RSACipherImpl</a></p>
<h2>Member Summary</h2>
<p><b>Member Functions: </b><a href="Poco.Crypto.Cipher.html#13" title="Poco::Crypto::Cipher::createDecryptor()">createDecryptor</a>, <a href="Poco.Crypto.Cipher.html#12" title="Poco::Crypto::Cipher::createEncryptor()">createEncryptor</a>, <a href="Poco.Crypto.Cipher.html#24" title="Poco::Crypto::Cipher::decrypt()">decrypt</a>, <a href="Poco.Crypto.Cipher.html#17" title="Poco::Crypto::Cipher::decryptString()">decryptString</a>, <a href="Poco.Crypto.Cipher.html#20" title="Poco::Crypto::Cipher::encrypt()">encrypt</a>, <a href="Poco.Crypto.Cipher.html#14" title="Poco::Crypto::Cipher::encryptString()">encryptString</a>, <a href="Poco.Crypto.Cipher.html#11" title="Poco::Crypto::Cipher::name()">name</a></p>
<p><b>Inherited Functions: </b><a href="Poco.RefCountedObject.html#9659" title="Poco::RefCountedObject::duplicate()">duplicate</a>, <a href="Poco.RefCountedObject.html#9661" title="Poco::RefCountedObject::referenceCount()">referenceCount</a>, <a href="Poco.RefCountedObject.html#9660" title="Poco::RefCountedObject::release()">release</a></p>
<h2>Types</h2>
<h3><a name="5">ByteVec</a></h3>
<p class="decl">typedef std::vector < unsigned char > <a href="Poco.Crypto.Cipher.html#5" title="Poco::Crypto::Cipher::ByteVec">ByteVec</a>;</p>
<div class="description">
<p></p>
</div>
<h3><a name="4">Ptr</a></h3>
<p class="decl">typedef <a href="Poco.AutoPtr.html" title="class Poco::AutoPtr">Poco::AutoPtr</a> < <a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a> > <a href="Poco.Crypto.Cipher.html#4" title="Poco::Crypto::Cipher::Ptr">Ptr</a>;</p>
<div class="description">
<p></p>
</div>
<h2>Enumerations</h2>
<h3><a name="6">Encoding</a></h3>
<div class="description">
<p>Transport encoding to use for <a href="Poco.Crypto.Cipher.html#14" title="Poco::Crypto::Cipher::encryptString()">encryptString</a>() and <a href="Poco.Crypto.Cipher.html#17" title="Poco::Crypto::Cipher::decryptString()">decryptString</a>(). </p>
</div>
<p class="decl"><a name="7">ENC_NONE</a></p>
<div class="description">
<p>Plain binary output </p>
</div>
<p class="decl"><a name="8">ENC_BASE64</a></p>
<div class="description">
<p>Base64-encoded output </p>
</div>
<p class="decl"><a name="9">ENC_BINHEX</a></p>
<div class="description">
<p>BinHex-encoded output </p>
</div>
<h2>Constructors</h2>
<h3><a name="28">Cipher</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a>();</p>
<div class="description">
<p>Creates a new <a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a> object. </p>
</div>
<h2>Destructor</h2>
<h3><a name="10">~Cipher</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual ~<a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a>();</p>
<div class="description">
<p>Destroys the <a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a>. </p>
</div>
<h2>Member Functions</h2>
<h3><a name="13">createDecryptor</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual <a href="Poco.Crypto.CryptoTransform.html" title="class Poco::Crypto::CryptoTransform">CryptoTransform</a> * createDecryptor() = 0;</p>
<div class="description">
<p>Creates a decryptor object to be used with a CryptoStream. </p>
</div>
<h3><a name="12">createEncryptor</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual <a href="Poco.Crypto.CryptoTransform.html" title="class Poco::Crypto::CryptoTransform">CryptoTransform</a> * createEncryptor() = 0;</p>
<div class="description">
<p>Creates an encrytor object to be used with a CryptoStream. </p>
</div>
<h3><a name="24">decrypt</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual void decrypt(<br /> std::istream & source,<br /> std::ostream & sink,<br /> <a href="Poco.Crypto.Cipher.html#6" title="enum Poco::Crypto::Cipher::Encoding">Encoding</a> encoding = ENC_NONE<br />);</p>
<div class="description">
<p>Directly decrypt an input stream that is encoded with the given encoding. </p>
</div>
<h3><a name="17">decryptString</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual std::string decryptString(<br /> const std::string & str,<br /> <a href="Poco.Crypto.Cipher.html#6" title="enum Poco::Crypto::Cipher::Encoding">Encoding</a> encoding = ENC_NONE<br />);</p>
<div class="description">
<p>Directly decrypt a string that is encoded with the given encoding. </p>
</div>
<h3><a name="20">encrypt</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual void encrypt(<br /> std::istream & source,<br /> std::ostream & sink,<br /> <a href="Poco.Crypto.Cipher.html#6" title="enum Poco::Crypto::Cipher::Encoding">Encoding</a> encoding = ENC_NONE<br />);</p>
<div class="description">
<p>Directly encrypts an input stream and encodes it using the given encoding. </p>
</div>
<h3><a name="14">encryptString</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual std::string encryptString(<br /> const std::string & str,<br /> <a href="Poco.Crypto.Cipher.html#6" title="enum Poco::Crypto::Cipher::Encoding">Encoding</a> encoding = ENC_NONE<br />);</p>
<div class="description">
<p>Directly encrypt a string and encode it using the given encoding. </p>
</div>
<h3><a name="11">name</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual const std::string & name() const = 0;</p>
<div class="description">
<p>Returns the name of the <a href="Poco.Crypto.Cipher.html" title="class Poco::Crypto::Cipher">Cipher</a>. </p>
</div>
<p class="footer">POCO C++ Libraries 1.3.6-all<br />
Copyright © 2009, <a href="http://pocoproject.org/" target="_blank">Applied Informatics Software Engineering GmbH and Contributors</a></p>
</div>
</body>
</html>
|