|
Using Encryption
| [Previous] [Main] [Next] |
|
| |
| Adding automatic encryption to html++ applications is easy. To do so, just instantiate any Coder-derived object representing the algorithm to use, then pass a pointer to that object to the htmlServer::Crypt() base-class method. If automatic decryption is also required, the Crypt() method should be used before the htmlServer object is initialized.
| |
|
| |
| The following example illustrates the technique:
| |
|
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| int main( void )
| |
| {
| |
| htmlPage page ;
| |
| ScrambleCoder coder( "mypassword" ) ;
| |
| htmlCgi server ;
| |
|
| |
| // Manually initialize the server object so that we
| |
| // can specify the encryption. This also enables
| |
| // automatic decryption as well.
| |
| server.Crypt( &coder ) ;
| |
| server.Initialize( cin ) ;
| |
|
| |
| htmlForm form( "/cgi-bin/formcrypt" );
| |
| form << htmlInputHidden( "creditcard",
| |
| "1234567890" ) ; // this part gets encrypted
| |
|
| |
| page << form ;
| |
|
| |
| // Output the page containing the form, performing
| |
| // automatic encryption on any hidden fields.
| |
| server << page ;
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
